How to do it...

This is a long class, so it is important to carefully follow these steps:

  1. First, create the rival's class, as follows:
using UnityEngine; 
using System.Collections; 
 
public class AirHockeyRival : MonoBehaviour 
{ 
    // next steps 
} 
  1. Next, declare the public variables for setting and tuning it up, as shown in the following code:
public GameObject puck; 
public GameObject paddle; 
public string goalWallTag = "GoalWall"; 
public string sideWallTag = "SideWall"; 
[Range(1, 10)] 
public int maxHits; 
  1. Declare the private variables, as follows:
float puckWidth; 
Renderer puckMesh; 
Rigidbody puckBody; 
AgentBehaviour agent; 
Seek seek; 
Leave leave; 
AHRState state; 
bool hasAttacked; 
  1. Implement the Awake member function for setting up private ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.