Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public List<Vector3> waypointPositions;
  2.  
  3.     public float speed = 1;
  4.  
  5.     int currentWaypoint = 0;
  6.  
  7.     Vector3 targetPositionDelta;
  8.  
  9.     Vector3 moveDirection = Vector3.zero;
  10.  
  11.     SpriteController spriteController;
  12.  
  13.  
  14.  
  15.  
  16.  
  17.     void Start () {
  18.  
  19.         spriteController = GetComponent<SpriteController>();
  20.  
  21.     }
  22.  
  23.  
  24.  
  25.    
  26.  
  27.     void Update () {
  28.  
  29.         Elevator();
  30.  
  31.         Move();
  32.  
  33.        
  34.  
  35.     }
  36.  
  37.  
  38.  
  39.     void Elevator() {
  40.  
  41.      
  42.  
  43.         Vector3 targetPosition = waypointPositions[currentWaypoint];
  44.  
  45.         targetPositionDelta = targetPosition - transform.position;
  46.  
  47.      
  48.  
  49.         if (targetPositionDelta.sqrMagnitude <= 1) {
  50.  
  51.  
  52.  
  53.  
  54.  
  55.          
  56.  
  57.             currentWaypoint ++;
  58.  
  59.          
  60.  
  61.             if(currentWaypoint>=waypointPositions.Count)
  62.  
  63.                 currentWaypoint = 0;
  64.  
  65.          
  66.  
  67.          
  68.  
  69.         }
  70.  
  71. void Move() {
  72.  
  73.      
  74.  
  75.         moveDirection = targetPositionDelta.normalized * speed;
  76.  
  77.         transform.Translate(moveDirection * Time.deltaTime,Space.World);
  78.  
  79.     }
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement