Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PatrolEnemy : MonoBehaviour
- {
- public Transform[] points;
- public Rigidbody2D therb;
- public CharecterAnimator charAnim;
- private int TarPoint;
- public float speed;
- // Start is called before the first frame update
- void Start()
- {
- charAnim= GetComponent<CharecterAnimator>();
- therb= GetComponent<Rigidbody2D>();
- TarPoint = 0;
- }
- // Update is called once per frame
- void Update()
- {
- if(transform.position == points[TarPoint].position)
- {
- IncreaseInt();
- }
- transform.position = Vector3.MoveTowards(transform.position, points[TarPoint].position, speed * Time.deltaTime);
- }
- private void IncreaseInt()
- {
- TarPoint++;
- if(TarPoint>= points.Length)
- {
- TarPoint= 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement