Hey guys, I’m working on a wave based zombie game. As of now I have the waves working perfectly. I would like to add a delay between waves and Im having no luck at all. Ive tried running a coroutine when the the enemiesKilled >= enemyAmount but it crashes my game. Any suggestions?
public int waveNumber = 0;
public int enemyAmount = 0;
public int enemiesKilled = 0;
public int randomEnemy;
public GameObject[ ] spawners;
public GameObject[ ] enemy;
public TextMeshProUGUI waveNumberText;
private void Start()
{
spawners = new GameObject[5];
for (int i = 0; i < spawners.Length; i++)
{
spawners = transform.GetChild(i).gameObject;
}
StartWave();
}
public void Update()
{
if (enemiesKilled >= enemyAmount)
{
NextWave();
}
waveNumberText.text = waveNumber.ToString(“0”);
}
public void SpawnEnemy()
{
int spawnerID = Random.Range(0, spawners.Length);
randomEnemy = Random.Range(0, enemy.Length);
Instantiate(enemy[randomEnemy], spawners[spawnerID].transform.position, spawners[spawnerID].transform.rotation);
}
public void StartWave()
{
waveNumber = 1;
enemyAmount = 6;
enemiesKilled = 0;
for (int i = 0; i < enemyAmount; i++)
{
SpawnEnemy();
}
}
public void NextWave()
{
waveNumber++;
enemyAmount += 4;
enemiesKilled = 0;
for (int i = 0; i < enemyAmount; i++)
{
SpawnEnemy();
}
}