Graphics Reference
In-Depth Information
The next four functions in the class are interface functions for other scripts to change
values, if needed:
public void SetReversePath( bool shouldRev )
{
shouldReversePathFollowing= shouldRev;
}
public void SetSpeed( float aSpeed )
{
moveSpeed= aSpeed;
}
public void SetPathSmoothingRate( float aRate )
{
pathSmoothing= aRate;
}
public void SetRotateSpeed( float aRate )
{
modelRotateSpeed= aRate;
}
UpdateWaypoints() takes care of keeping the current target waypoint up to date and
carries out self-destruction, if required, when the AI reaches the end of the path.
It begins with a check to make sure that myWayControl (a reference to an instance
of Waypoints_Controller.cs) is not null, which should mean that the SetWayController()
function has been called by another script and set up successfully:
void UpdateWaypoints()
{
// If we don't have a waypoint controller, we safely drop out
if( myWayControl==null )
return;
The AI controller script has the option to automatically destroy itself when the last
waypoint is reached. When destroyAtEndOf Waypoints is set to true, the gameObject is
destroyed, and this code drops out of the UpdateWaypoints() script immediately.
When destroyAtEndOf Waypoints is false, the assumption is that waypoint following
should go back to the beginning; currentWaypointNum is set to zero, reachedLastWay-
point is reset, and the AI is free to start over again:
if( reachedLastWaypoint && destroyAtEndOfWaypoints )
{
// destroy myself(!)
Destroy( gameObject );
return;
} else if( reachedLastWaypoint )
{
currentWaypointNum= 0;
reachedLastWaypoint= false;
}
To keep this function safe (just in case it is somehow called before the waypoints
have been correctly set up by the Waypoints_Controller.cs script), there is a check to
Search WWH ::




Custom Search