Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EnemyPatrol : EnemyTouch
- {
- public float minX;
- public float maxX;
- public float minY;
- public float maxY;
- Vector2 targetPosition;
- public float speed;
- public float speedTimer = 1f;
- public float speedBoost = 1f;
- // Start is called before the first frame update
- void Start()
- {
- targetPosition = GetRandomPosition();
- }
- // Update is called once per frame
- void Update()
- {
- if ((Vector2)transform.position != targetPosition)
- {
- transform.position = Vector2.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
- }
- else
- {
- targetPosition = GetRandomPosition();
- }
- /* if ((Vector2)transform.position != targetPosition && EnemyTouchAndScore()==true )
- {
- StartCoroutine(BoostSpeedCo());
- }*/
- }
- Vector2 GetRandomPosition()
- {
- float randomX = Random.Range(minX, maxX);
- float randomY = Random.Range(minY, maxY);
- return new Vector2(randomX, randomY);
- }
- IEnumerator BoostSpeedCo()
- {
- transform.position = Vector2.MoveTowards(transform.position, targetPosition, speedBoost + speed * Time.deltaTime);
- yield return new WaitForSeconds(speedTimer);
- // transform.position = Vector2.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
- }
- // Start is called before the first frame update
- void Start()
- {
- targetPosition = GetRandomPosition();
- }
- // Update is called once per frame
- void Update()
- {
- if ((Vector2)transform.position != targetPosition)
- {
- transform.position = Vector2.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
- }
- else
- {
- targetPosition = GetRandomPosition();
- }
- }
- Vector2 GetRandomPosition()
- {
- float randomX = Random.Range(minX, maxX);
- float randomY = Random.Range(minY, maxY);
- return new Vector2(randomX, randomY);
- }
- IEnumerator BoostSpeedCo()
- {
- transform.position = Vector2.MoveTowards(transform.position, targetPosition, speedBoost * Time.deltaTime);
- Debug.Log("boosted");
- yield return new WaitForSeconds(speedTimer);
- // transform.position = Vector2.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement