duck

duck

Oct 5th, 2010
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1.  
  2.  
  3. public class droidScript : MonoBehaviour {
  4.  
  5.     public Collider[] movementZones;
  6.     public moveSpeed = 2;
  7.     private zoneNum = 0;
  8.     private Vector3 target;
  9.     private zoneTime = 0;
  10.     private Vector3 lastPosition;
  11.    
  12.     void Start() {
  13.         PickTarget()
  14.     }
  15.  
  16.     void PickTarget() {
  17.         lastPosition = transform.position;
  18.         Bounds zone = movementZones[zoneNum].bounds;
  19.         float targetX = zone.min.x + zone.size.x * Random.value;
  20.         float targetY = zone.min.y + zone.size.y * Random.value;
  21.         float targetZ = zone.min.z + zone.size.z * Random.value;
  22.         target = new Vector3( targetX, targetY, targetZ );
  23.         zoneTime = 0;
  24.     }  
  25.    
  26.     void Update() {
  27.         zoneTime += Time.time * moveSpeed;
  28.         transform.position = Vector3.Lerp(lastPosition, target, zoneTime);
  29.         if (zoneTime >= 1)
  30.         {
  31.             zoneNum++;
  32.             if (zoneNum < movementZones.Length)
  33.             {
  34.                 PickTarget();
  35.             } else {
  36.                 // Destroy!!!
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment