duck

finding numbered waypoints in Unity javascript

May 28th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. public var wayPoint01: GameObject;
  4.  
  5. private var enemiesAlive: int = 0;
  6. private var lerpSpeed: float = 0;
  7.  
  8. //declaring the array i want the children to be listed in
  9. var waypoints = new Array ();
  10.  
  11. //created a reference to the parent GO i want to take the children from.
  12. public var wayPointsContainer : Transform;
  13.  
  14. function Start () {
  15.  
  16.     // find and store all waypoints in order
  17.     var n = 1;
  18.     var foundWaypoint = true;
  19.     while (foundWaypoint)
  20.     {
  21.         var newWaypoint = wayPointsContainer.Find("waypoint"+(n.ToString("00")));
  22.         if (newWaypoint != null)
  23.         {
  24.             waypoints.Push(newWaypoint);
  25.             Debug.Log("found waypoint "+newWaypoint.name);
  26.         } else {
  27.             Debug.Log("finished, found "+waypoints.length+" waypoints");
  28.             foundWaypoint = false;
  29.         }
  30.     }
  31.  
  32. }
  33.      
  34. function Update () {
  35.    
  36.     var listOfEnemies : GameObject[] = getEnemiesAlive();
  37.     if (listOfEnemies.length == 0)
  38.     {
  39.         //Debug.Log("No Enemies Left");
  40.         lerpSpeed += Time.deltaTime * 0.05;
  41.         transform.position = Vector3.Lerp(transform.position, wayPoint01.transform.position, lerpSpeed);
  42.     }
  43.     else
  44.     {
  45.         //Debug.Log("Enemies Left");
  46.     }
  47. }
  48.      
  49. function getEnemiesAlive()
  50. {
  51.     return GameObject.FindGameObjectsWithTag ("Enemy");
  52. }
Advertisement
Add Comment
Please, Sign In to add comment