using System.Collections; using System.Collections.Generic; using UnityEngine; public class Boss2Controller : MonoBehaviour { [SerializeField] Rigidbody2D body; [SerializeField] float waitTime = 8f; [SerializeField] float smoothness = 20f; [SerializeField] float maxSpeed = 150f; [SerializeField] int border = 64; [SerializeField] GameObject bullet; float intentX = 0; float intentY = 0; AudioSource audioSource; PLIGameController game; // 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() { intentX = ((transform.position.x > 0) ? 1 : -1) * 100; intentY = 0; yield return new WaitForSeconds(waitTime); intentX = ((transform.position.x > 0) ? -1 : 1) * 150; intentY = 100; yield return new WaitForSeconds(waitTime); intentX = ((transform.position.x > 0) ? 1 : -1) * 80; intentY = 50; yield return new WaitForSeconds(waitTime); intentX = ((transform.position.x > 0) ? -1 : 1) * 170; intentY = 0; yield return new WaitForSeconds(waitTime); intentX = transform.position.x; intentY = -300; yield return new WaitForSeconds(waitTime); Destroy(gameObject); } IEnumerator GoCraCy() { yield return new WaitForSeconds(5.0f); while (true) { float bulletsPerRevolution = 10f; float bulletSpeed = 40f; int c = 0; float a = 0f; while (c < 15) { c++; GameObject b1 = Instantiate(bullet); b1.transform.position = transform.position; b1.GetComponent().velocity = new Vector2( 1.0f * bulletSpeed * Mathf.Cos(a), 1.0f * bulletSpeed * Mathf.Sin(a)); GameObject b2 = Instantiate(bullet); b2.transform.position = transform.position; b2.GetComponent().velocity = new Vector2( 1.5f * bulletSpeed * Mathf.Cos(a + Mathf.PI / 8), 1.5f * bulletSpeed * Mathf.Sin(a + Mathf.PI / 8)); GameObject b3 = Instantiate(bullet); b3.transform.position = transform.position; b3.GetComponent().velocity = new Vector2( 2.0f * bulletSpeed * Mathf.Cos(a - Mathf.PI / 8), 2.0f * bulletSpeed * Mathf.Sin(a - Mathf.PI / 8)); a += 2 * Mathf.PI / bulletsPerRevolution; yield return new WaitForSeconds(0.05f); } yield return new WaitForSeconds(3f); } } // Update is called once per frame void FixedUpdate() { Vector2 vel = body.velocity; Vector2.SmoothDamp(transform.position, new Vector2(intentX, intentY), ref vel, smoothness, maxSpeed); body.velocity = vel; } }