VitalyD

Untitled

Mar 8th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. namespace Assets
  4. {
  5.     public class MovePoly : MonoBehaviour
  6.     {
  7.         public Transform[] Targets;
  8.         private int _tindex = 0;
  9.    
  10.         void Start()
  11.         {
  12.             transform.position = Targets[_tindex].transform.position;
  13.         }
  14.    
  15.         void Update()
  16.         {
  17.             Move();
  18.         }
  19.  
  20.         void Move()
  21.         {
  22.             transform.position =
  23.                 Vector2.MoveTowards(transform.position, Targets[_tindex].transform.position, Time.deltaTime);
  24.  
  25.             if (transform.position == Targets[_tindex].transform.position) _tindex += 1;
  26.  
  27.             if (_tindex == Targets.Length) _tindex = 0;
  28.         }
  29.     }
  30. }
Add Comment
Please, Sign In to add comment