Advertisement
Guest User

Script 2

a guest
Feb 23rd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. public class EnemyPatrol : EnemyTouch
  2. {
  3.     public float minX;
  4.     public float maxX;
  5.     public float minY;
  6.     public float maxY;
  7.     Vector2 targetPosition;
  8.     public float speed;
  9.     public float speedTimer = 1f;
  10.     public float speedBoost = 1f;
  11.  
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.         targetPosition = GetRandomPosition();
  16.     }
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         if ((Vector2)transform.position != targetPosition)
  21.         {
  22.             transform.position = Vector2.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
  23.          
  24.  
  25.         }
  26.         else
  27.         {
  28.             targetPosition = GetRandomPosition();
  29.         }
  30.  
  31.        /* if ((Vector2)transform.position != targetPosition && EnemyTouchAndScore()==true )
  32.         {
  33.             StartCoroutine(BoostSpeedCo());
  34.  
  35.  
  36.         }*/
  37.     }
  38.     Vector2 GetRandomPosition()
  39.     {
  40.         float randomX = Random.Range(minX, maxX);
  41.         float randomY = Random.Range(minY, maxY);
  42.         return new Vector2(randomX, randomY);
  43.     }
  44.     IEnumerator BoostSpeedCo()
  45.     {
  46.         transform.position = Vector2.MoveTowards(transform.position, targetPosition, speedBoost + speed * Time.deltaTime);        
  47.         yield return new WaitForSeconds(speedTimer);
  48.         // transform.position = Vector2.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);      
  49.  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement