Graphics Reference
In-Depth Information
he Waypoints_Controller.cs script is very similar to the one from my last topic, Game
Development for iOS with Unity3D (also published by CRC Press). The waypoints controller
here has been converted over to C# from its original JavaScript form:
public class Waypoints_Controller : MonoBehavior
{
[ExecuteInEditMode]
// this script simply gives us a visual path to make it easier to edit
// our waypoints
private ArrayList transforms; // arraylist for easy access to
// transforms
private Vector3 firstPoint; // store our first waypoint so we can
// loop the path
private float distance; // used to calculate distance between
// points
private Transform TEMPtrans; // a temporary holder for a transform
private int TEMPindex; // a temporary holder for an index number
private int totalTransforms;
private Vector3 diff;
private float curDistance;
private Transform closest;
private Vector3 currentPos;
private Vector3 lastPos;
private Transform pointT;
public bool closed=true;
public bool shouldReverse;
void Start()
{
// make sure that when this script starts that
// we have grabbed the transforms for each waypoint
GetTransforms();
}
void OnDrawGizmos()
{
// we only want to draw the waypoints when we're editing,
// not when we are playing the game
if( Application.isPlaying )
return;
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
Search WWH ::




Custom Search