void SpawnEnemy() { Vector3 newSpawnPos = Player.instance.transform.position + new Vector3(enemySpawnOffset + UnityEngine.Random.Range(0, 3), 0, 0); if (Vector3.Distance(newSpawnPos, _lastSpawnPosition) <= enemySpawnDistance) { return; } if ((_enemiesSpawned % bossSpawnRate) == 0) { if (_bossAlive && !_bossActive) { _zombieBoss.GetComponent <Rigidbody>().velocity = Vector3.zero; _zombieBoss.transform.position = _lastSpawnPosition = newSpawnPos; _bossActive = true; _bossGameObjectActive = true; _enemiesSpawned++; } else if (!_bossAlive) { Transform enemyTransform = (Transform)Instantiate(bossPrefabs[_bossesSpawned % bossPrefabs.Length]); _zombieBoss = enemyTransform.gameObject.GetComponent <ZombieBoss>(); _zombieBoss.OnDeath += OnBossDeath; _zombieBoss.OnZombieBossLaunch += OnZombieBossLaunch; enemyTransform.position = _lastSpawnPosition = newSpawnPos; enemyTransform.parent = transform; _bossActive = true; _bossesSpawned++; _enemiesSpawned++; } } else if (!_bossActive) { Transform enemyTransform = (Transform)Instantiate(enemyPrefabs[UnityEngine.Random.Range(0, enemyPrefabs.Length)]); enemyTransform.position = _lastSpawnPosition = newSpawnPos; enemyTransform.parent = transform; _enemiesSpawned++; } }
IEnumerator OnZombieBossDeath() { yield return(new WaitForSeconds(1.5f)); _zombieBoss = null; }