This question was
closed Mar 02, 2020 at 01:44 AM by
tormentoarmagedoom for the following reason:
Too subjective and argumentative
Question by
aatishkumarsingh30 · Mar 01, 2020 at 08:47 PM ·
tower-defense
how to stop spawning wave after game over
public static int EnemyAlive = 0;
public Wave[] waves;
public Transform[] spawnPoint;
public float timeBetweenWaves = 5f;
private float countdown = 1f;
public Text waveCountdownText;
public Gamemanager gameManager;
private int waveIndex = 0;
private void Start()
{
EnemyAlive = 0;
}
void Update()
{
if (EnemyAlive > 0)
{
return;
}
if (waveIndex == waves.Length)
{
if (PlayerStats.Lives> 0)
{
gameManager.WinLevel();
this.enabled = false;
return;
}
}
if (countdown <= 0f)
{
StartCoroutine(SpawnWave());
countdown = timeBetweenWaves;
return;
}
countdown -= Time.deltaTime;
}
IEnumerator SpawnWave()
{
Wave wave = waves[waveIndex];
EnemyAlive = wave.count;
for (int i = 0; i < wave.count; i++)
{
SpawnEnemy(wave.enemy);
yield return new WaitForSeconds(1f / wave.rate);
}
waveIndex++;
}
void SpawnEnemy(GameObject enemy)
{
Transform _sp = spawnPoint[Random.Range(0, spawnPoint.Length)];
Instantiate(enemy, _sp.position, _sp.rotation);
}
}
Comment