Graphics Reference
In-Depth Information
drag waypoints. Comment out the line above if you find you are having trouble with
automatically rotating points.
As the function continues, we continue to iterate through the waypoints and
then close the path, if the Boolean variable closed is set to true (you can set that in the
Inspector window of the editor when the gameObject that has this script attached is
selected):
// update our 'last' waypoint to become this one as
// we move on to find the next...
lastPos = currentPos;
// update the pointing transform
pointT=(Transform)transforms[i];
}
// close the path
if(closed)
{
Gizmos.color=Color.red;
Gizmos.DrawLine(currentPos, firstPoint);
}
}
After the GetTransforms() function discussed earlier, the rest of the class is made up
of publically accessible utility functions for other scripts to access:
SetReverseMode
Sets the value of a Boolean variable called shouldReverse, which determines
whether or not the path should be reversed.
FindNearestWaypoint
Finds the nearest waypoint to a given position, within a given distance, and
returns its index number as an integer.
There are two implementations of the FindNearestWaypoint function, one of
which adds the extra parameter of exceptThis. The function will find the
closest waypoint as normal, but when exceptThis is used it will ignore the
specified transform.
GetWaypoint
Returns the transform of the waypoint at the index number passed in (as an
integer).
GetTotal
Returns an integer value representing the total number of waypoints this
class has control over.
public void SetReverseMode(bool rev)
{
shouldReverse=rev;
}
public int FindNearestWaypoint (Vector3 fromPos, float maxRange)
{
// make sure that we have populated the transforms
// list, if not, populate it
if(transforms==null)
GetTransforms();
Search WWH ::




Custom Search