12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EnemyControl : MonoBehaviour
- {
- public Vector2 startWait;
- public Vector2 maneuverTime;
- public Vector2 maneuverWait;
- public float dodge;
-
- public float speed;
- private float targetmaneuver;
-
- // Use this for initialization
- void Start()
- {
- StartCoroutine(RandomDir());
- }
- // Update is called once per frame
- void Update()
- {
- }
- void FixedUpdate()
- {
- float newMan = Mathf.MoveTowardsAngle(transform.eulerAngles.z, targetmaneuver, Time.deltaTime * 10);
- transform.rotation = Quaternion.Euler(0, 0, newMan);
- transform.Translate(Vector3.up * Time.deltaTime * speed);
- }
- IEnumerator RandomDir()
- {
- yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
- while (true)
- {
- targetmaneuver = Random.Range(1, dodge) * -Mathf.Sign(transform.eulerAngles.z);
- yield return new WaitForSeconds(Random.Range(maneuverTime.x, maneuverTime.y));
- targetmaneuver = 0;
- yield return new WaitForSeconds(Random.Range(maneuverWait.x, maneuverWait.y));
- }
- }
- }
|