I have a very basic top down shooter game that I want to work kind of like Call of Duty nazi zombies. However, for some reason every time the last enemy spawns and I have still yet to shoot him, the game will proceed to the next wave. Here’s my code below, any help would be much appreciated
`
GameObject enemy;
public GameObject zombieA;
public GameObject spawnPoint;
Vector3 spawnPointPos;
float respawnMinBase = 3.0f;
float respawnMaxBase = 10.0f;
float respawnMin = 3.0f;
float respawnMax = 10.0f;
float respawnInterval = 2.5f;
float enemyCount = 5f; //Check to make sure enemies are all gone befoe preceding to next wave
float lastSpawnTime = 0;
// Use this for initialization
void Start () {
enemy = GameObject.FindGameObjectWithTag ("Enemy");
spawnPoint = GameObject.FindGameObjectWithTag ("Spawn");
spawnPointPos = spawnPoint.transform.position;
SetNextWave ();
StartNewWave ();
}
// Update is called once per frame
void Update () {
Debug.Log ("Wave: " + waveLevel);
Debug.Log ("Enemies left: " + enemyCount);
//Check for remaining enemies
if (enemyCount <= 0) {
Debug.Log("Wave Won!");
spawnEnemies = false;
if(Time.time >= waveEndTime){
SetNextWave();
StartNewWave();
}
}
if (spawnEnemies) {
if(Time.time > (lastSpawnTime + respawnInterval)) //wave is still going spawn enemies
{
SpawnEnemy();
}
}
}void SetNextWave(){
waveLevel ++;
difficultyMultiplier = ((Mathf.Pow (waveLevel, 2)) * .05f) + 1; //Up the level exponentially
enemyCount = 5f;
enemyCount += difficultyMultiplier;
respawnMin = respawnMinBase * (1 / difficultyMultiplier);
respawnMax = respawnMaxBase * (1 / difficultyMultiplier);
}
void StartNewWave(){
//Update GUI function
//Spawn New Enemy function to spawn the first enemy
//Set the wave end time
waveEndTime = Time.time + waveLength;
//Activate the wave
waveActive = true;
spawnEnemies = true;
}
void SpawnEnemy(){
Instantiate (zombieA, spawnPointPos, Quaternion.identity);
//Let the game an enemy is added
enemyCount--;
//Set the current time as the last spawn time
lastSpawnTime = Time.time;
//Re-randomize the respawn interval
respawnInterval = Random.Range (respawnMin, respawnMax);
}
}`