This question was
closed Nov 25, 2016 at 11:42 AM by
hexagonius.
Question by
boolean89 · Nov 25, 2016 at 07:57 AM ·
enemy spawnwaves
I want to be able to spawn a certain amount of enemies in a wave, but instead it just keeps infinitely spawning enemies
public PlayerHealth playerHealth;
public GameObject enemy;
public float spawnTime = 3f;
public Transform[] spawnPoints;
int totalEnemies = 17;
int livesEnemies = 0;
float waitToWave = 15;
float waveTime;
void Start ()
{
InvokeRepeating ("Spawn", spawnTime, spawnTime);
}
void Spawn ()
{
if(playerHealth.currentHealth <= 0f)
{
return;
}
int spawnPointIndex = Random.Range(0, spawnPoints.Length);
if (livesEnemies == 0)
{
if (waitToWave <= waveTime)
{
waveTime = 0;
livesEnemies = totalEnemies;
for (int i = 0; i < totalEnemies; i++)
Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
}
else
{
waveTime += Time.deltaTime;
}
}
}
Comment
Follow this Question
Related Questions
Survival Shooter Spawn Enemies in Waves? 0 Answers
wave spawner difficulty increase 1 Answer
Wave Spawner does not spawn Next wave? 0 Answers
How do i add a enemy multiplier to my wave spawner? 1 Answer
Help with timed wave defense game 0 Answers