Graphics Reference
In-Depth Information
Before advancing to the next waypoint, shouldReversePathFollowing is checked to
see which direction along the path it needs to go. When its value is true, the value of cur-
rentWaypointNum is decremented:
if( shouldReversePathFollowing )
{
currentWaypointNum--;
If the path is reversed, when currentWaypointNum drops below zero, it needs
to get reset to the waypoint at the other end of the path (only when loopPath is set).
To make this happen, currentWaypointNum will be set to the value of the variable
totalWay points.
Something else that happens in this chunk of code, when we know that the end of the
path has been reached, is that the value of reachedLastWaypoint is set to true. This will be
checked on the next UpdateWaypoints() call to carry out any actions that need to be done
at the end of the path (such as destroying the gameObject when destroyAtEndOf Way-
points is set to true):
// now check to see if we have been all the way around
if( currentWaypointNum<0 ){
// just in case it gets referenced before we
// are destroyed, let's keep it to a safe
// index number
currentWaypointNum= 0;
// completed the route!
reachedLastWaypoint= true;
// if we are set to loop, reset the
// currentWaypointNum to 0
if(loopPath)
{
currentWaypointNum= totalWaypoints;
// the route keeps going in a loop,
// so we don't want reachedLastWaypoint
// to ever become true
reachedLastWaypoint= false;
}
// drop out of this function before we grab
// another waypoint into currentWaypoint
// Transform, as we don't need one and the
// index may be invalid
return;
}
} else {
The shouldReversePathFollowing Boolean must have been set to false for the fol-
lowing code to be executed, meaning that the currentWaypointNum has gone past the
final waypoint in the list held by the waypoints controller and that currentWaypointNum
needs to be reset to zero if the variable loopPath is set to true:
currentWaypointNum++;
// now check to see if we have been all the way around
if( currentWaypointNum>=totalWaypoints ){
Search WWH ::




Custom Search