EnemyControl.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class EnemyControl : MonoBehaviour
  5. {
  6. public Vector2 startWait;
  7. public Vector2 maneuverTime;
  8. public Vector2 maneuverWait;
  9. public float dodge;
  10. public float speed;
  11. private float targetmaneuver;
  12. // Use this for initialization
  13. void Start()
  14. {
  15. StartCoroutine(RandomDir());
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. }
  21. void FixedUpdate()
  22. {
  23. float newMan = Mathf.MoveTowardsAngle(transform.eulerAngles.z, targetmaneuver, Time.deltaTime * 10);
  24. transform.rotation = Quaternion.Euler(0, 0, newMan);
  25. transform.Translate(Vector3.up * Time.deltaTime * speed);
  26. }
  27. IEnumerator RandomDir()
  28. {
  29. yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
  30. while (true)
  31. {
  32. targetmaneuver = Random.Range(1, dodge) * -Mathf.Sign(transform.eulerAngles.z);
  33. yield return new WaitForSeconds(Random.Range(maneuverTime.x, maneuverTime.y));
  34. targetmaneuver = 0;
  35. yield return new WaitForSeconds(Random.Range(maneuverWait.x, maneuverWait.y));
  36. }
  37. }
  38. }