Advertisement
GoodNoodle

Patrol.cs

Sep 9th, 2023
1,337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. public class PatrolEnemy : MonoBehaviour
  2. {
  3.  
  4.     public Transform[] points;
  5.  
  6.     public Rigidbody2D therb;
  7.  
  8.     public CharecterAnimator charAnim;
  9.  
  10.     private int TarPoint;
  11.  
  12.     public float speed;
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         charAnim= GetComponent<CharecterAnimator>();
  17.         therb= GetComponent<Rigidbody2D>();
  18.  
  19.         TarPoint = 0;
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.         if(transform.position == points[TarPoint].position)
  26.         {
  27.             IncreaseInt();
  28.         }
  29.       transform.position = Vector3.MoveTowards(transform.position, points[TarPoint].position, speed * Time.deltaTime);
  30.     }
  31.  
  32.     private void IncreaseInt()
  33.     {
  34.         TarPoint++;
  35.  
  36.         if(TarPoint>= points.Length)
  37.         {
  38.             TarPoint= 0;
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement