Script is here, the focus point is on lines with the “//”
The context is that not all of the enemies are removed from the list since they all have the same name, so because of this, we cannot move on to the next wave. I need a solution.
Thanks!
[Header("Wave Stuff")]
[SerializeField] private TextMeshProUGUI waveCountdown;
[SerializeField] private GameObject enemy;
[SerializeField] private GameObject[] spawnPoints;
[SerializeField] private float enemySpawnInterval = 10f;
private bool enemySpawned;
private int currentWave = 1;
[SerializeField] private float enemiesToSpawn = 1;
private int currentEnemies = 0;
private GameObject enemyClone;
[SerializeField] private List<GameObject> runtimeCreatedObjects;
private void WaveSystem()
{
if(enemySpawned == false)
{
enemySpawnInterval -= Time.deltaTime;
}
waveCountdown.text = "Wave Begins In: " + Mathf.Round(enemySpawnInterval);
if(enemySpawnInterval <= 0 && enemySpawned == false && currentEnemies != Mathf.Round(enemiesToSpawn))
{
// enemyClone = Instantiate(enemy, spawnPoints[Random.Range(0, //spawnPoints.Length)].transform.position, spawnPoints[0].transform.rotation);
// runtimeCreatedObjects.Add(enemyClone);
// currentEnemies++;
if(currentEnemies == Mathf.Round(enemiesToSpawn))
{
enemySpawned = true;
currentWave++;
currentEnemies = 0;
}
}
// if(enemyClone == null )
// {
// runtimeCreatedObjects.Remove(enemyClone);
// if(runtimeCreatedObjects.Count == 0 && enemySpawned == true && currentWave <= 3)
// {
// enemySpawned = false;
// enemySpawnInterval = 15f;
// enemiesToSpawn += 2;
// }
}else if(enemyClone == null )
{
runtimeCreatedObjects.Remove(enemyClone);
if(runtimeCreatedObjects.Count == 0 && enemySpawned == true && currentWave <= 5)
{
enemySpawned = false;
enemySpawnInterval = 15f;
enemiesToSpawn += 2;
}
}
else if(enemyClone == null )
{
runtimeCreatedObjects.Remove(enemyClone);
if(runtimeCreatedObjects.Count == 0 && enemySpawned == true && currentWave > 5)
{
enemySpawned = false;
enemySpawnInterval = 15f;
enemiesToSpawn += 2;
}
}
}