Graphics Reference
In-Depth Information
In this game, as there are properties we need to set through the Unity editor Inspector
window, there will always be a BaseAIController component attached to the enemy pre-
fabs, but in the event that no BaseAIController component has been attached to this
object, this script uses GameObject.AddComponent() to make a new one. This is mainly
so that the script can be reused in other games:
if(AIController==null)
AIController= myGO.AddComponent<BaseAIController>();
The AIController needs to be initialized:
// run the Init function from our base class
// (BaseAIController.cs)
AIController.Init();
AIController.SetAIControl() tells the AI controller that it can control this enemy. Its
SetAIState() function is called next, setting the state to translate_along_waypoint_path
(see Chapter 9 of this topic for a full breakdown of AIStates and the BaseAIController.cs
script):
// tell AI controller that we want it to control this object
AIController.SetAIControl(true);
// tell our AI to follow waypoints
AIController.SetAIState( AIStates.AIState.translate_along_waypoint_path );
// set a flag to tell us that init has happened
didInit= true;
}
SetWayController() will be called by the game controller to tell this script which
Waypoints_Controller instance to use. Once this function has it, a call to AIController.
SetWayController() passes on the reference:
public virtual void SetWayController( Waypoints_Controller
aWaypointControl )
{
if(AIController==null)
Init ();
// pass this on to our waypoint controller, so that it can
// follow the waypoints
AIController.SetWayController(aWaypointControl);
}
}
Search WWH ::




Custom Search