Graphics Reference
In-Depth Information
void OnDrawGizmos()
{
// we only want to draw the waypoints when we're editing,
// not when we are playing the game
if( Application.isPlaying )
return;
Application.Playing can be checked to find out whether or not Unity is in edit mode
or playing your game. There is no point in wasting time or CPU cycles drawing waypoints
when the game is running, so we did a quick check to drop out whenever we are not in
edit mode.
The next steps are to keep the transforms up to date (just in case they are moved or
new ones added in the editor). Also, when you first build a path, obviously it will start with
a single waypoint. With only one point, there is no end point for rendering a line in the
editor, so this function checks that there are enough waypoints to actually draw a line and
drops out when totalTransforms is less than 2.
GetTransforms();
// make sure that we have more than one transform in the
// list, otherwise we can't draw lines between them
if (totalTransforms < 2)
return;
// draw our path first, we grab the position of the very
// first waypoint so that our line has a start point
TEMPtrans = (Transform)transforms[0];
lastPos = TEMPtrans.position;
// we point each waypoint at the next, so that we can use
// this rotation data to find out when the player is going
// the wrong way or to position the player after a reset
// facing the correct direction. So first we need to hold a
// reference to the transform we are going to point
pointT = (Transform)transforms[0];
// also, as this is the first point we store it to use for
// closing the path later
firstPoint = lastPos;
// now we loop through all of the waypoints drawing lines
// between them
for (int i = 1; i < totalTransforms; i++)
{
TEMPtrans = (Transform)transforms[i];
if(TEMPtrans==null)
{
GetTransforms();
return;
}
// grab the current waypoint position
currentPos = TEMPtrans.position;
Search WWH ::




Custom Search