using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyController_Dummy : MonoBehaviour { [SerializeField] Rigidbody2D body; [SerializeField] float waitTime = 5f; [SerializeField] float smoothness = 1f; [SerializeField] int border = 64; [SerializeField] GameObject bullet; float intentX = 0; float intentY = 0; AudioSource audioSource; PLIGameController game; bool slow = false; // Start is called before the first frame update void Start() { body = GetComponent(); game = GameObject.FindGameObjectWithTag("PegLegIoGame").GetComponent(); audioSource = game.GetComponent(); StartCoroutine(PickSomewhere()); StartCoroutine(GoCraCy()); } IEnumerator PickSomewhere() { for (int i = 0; i < 5; i++) { intentX = ((transform.position.x > 0) ? 1 : -1) * Random.Range(0f, 170f); intentY = Random.Range(0f, 100f); yield return new WaitForSeconds(waitTime); } slow = true; intentX = transform.position.x; intentY = -300; yield return new WaitForSeconds(waitTime); Destroy(gameObject); } IEnumerator GoCraCy() { yield return new WaitForSeconds(3.0f); while (true) { float bulletsPerRevolution = 15f; float bulletSpeed = 100f; int c = 0; float a = 0f; while (c < 30) { c++; GameObject b1 = Instantiate(bullet); b1.transform.position = transform.position; b1.GetComponent().velocity = new Vector2( bulletSpeed * Mathf.Cos(a), bulletSpeed * Mathf.Sin(a)); a += 2 * Mathf.PI / bulletsPerRevolution; yield return new WaitForSeconds(0.01f); } yield return new WaitForSeconds(5f); } } // Update is called once per frame void FixedUpdate() { Vector2 vel = body.velocity; Vector2.SmoothDamp(transform.position, new Vector2(intentX, intentY), ref vel, (slow?5:smoothness)); body.velocity = vel; } }