// Start is called before the first frame update void Awake() { if (_instance != null && _instance != this) { Destroy(gameObject); return; } _instance = this; }
void Update() { ShmupController shmup = ShmupController.Instance; float spawnX = Random.Range(shmup.VerticalMarginSize, shmup.Width - shmup.VerticalMarginSize); if (Time.fixedTime >= nextSpawnTime) { GameObject enemy = Instantiate(baseEnemyPrefab, shmup.transform.position + new Vector3(spawnX, shmup.Height, 0), transform.rotation); enemy.transform.SetParent(ShmupController.Instance.transform); GameObject actionObject = enemy.transform.GetChild(0).gameObject; float rand = Random.Range(0, 100); if (rand <= 75f) { MoveAction action = actionObject.AddComponent <MoveAction>(); action.MoveAmount = 1; float directionRand = Random.Range(0, 100); if (directionRand <= 40f) { action.Direction = MoveAction.MoveDirection.Left; } else if (directionRand <= 80f) { action.Direction = MoveAction.MoveDirection.Right; } else { action.Direction = MoveAction.MoveDirection.Down; } } else { RotateAction action = actionObject.AddComponent <RotateAction>(); switch ((int)Random.Range(0, 1.99f)) { case 0: action.Direction = RotateAction.RotateDirection.Clockwise; break; default: action.Direction = RotateAction.RotateDirection.CounterClockwise; break; } } Rigidbody2D rb = enemy.GetComponent <Rigidbody2D>(); rb.velocity = -transform.up * Random.Range(minMoveSpeed, maxMoveSpeed); nextSpawnTime = Time.fixedTime + Random.Range(minSpawnInterval, maxSpawnInterval); } }