Graphics Reference
In-Depth Information
Obviously, before trying to access the waypoint transforms to send out as a return
value, it is important to make sure that they have been set up; so there's a quick check to
make sure that transforms is not null. If transforms is null, we know that there will be no
transforms to work with so GetTransforms() is called to get everything set up:
// make sure that we have populated the transforms list, if
// not, populate it
if(transforms==null)
GetTransforms();
If the index being requested is too high, rather than return a wrong waypoint it will
return a null value. The code on the requesting side can then check for a null return value
and act accordingly:
// first, let's check to see if this index is higher than
// our waypoint count
// if so, we return null which needs to be handled on the
// other side'
if(index>totalTransforms-1)
return null;
Now that everything has been set up correctly (the transforms list contains waypoints
and the index number is within range), all that is left to do is return the transform from
the array:
return (Transform)transforms[index];
}
The final piece in the waypoints controller script is GetTotal(), which is used by other
scripts to find out how many waypoints there are:
public int GetTotal()
{
return totalTransforms;
}
}
Search WWH ::




Custom Search