- Home /
Spawner control and ending the level
Hi,
I am making a 2D game in which enemies will spawn throughout the level to attack the player. After a certain amount of enemies have been defeated, the spawner will stop spawning enemies and, after you kill the last remaining ones, the level should end.
I am having trouble with stopping the spawner and ending the level. I have recently fixed the spawner problem which was due to my carelessness. The more important question is how can I detect whether or not the scene contains enemies?
Here are 2 variations of the LevelisClear() check that I have tried:
public bool levelIsClear()
{
if (GameObject.FindGameObjectsWithTag("Enemy") == null &&
GameObject.FindGameObjectsWithTag("Ground") == null &&
GameObject.FindGameObjectsWithTag("Hardcore") == null)
return true;
else return false;
}
public bool levelIsClear()
{
if (GameObject.Find("Enemy1(Clone)") == null &&
GameObject.Find("Groundguy(Clone)") == null &&
GameObject.Find("Hardcore(Clone)") == null)
return true;
else return false;
}
I'm not sure about these as they contain Unity exclusive functions that I don't have much experience with. Am I using them correctly? Or is there a better way to check for enemy presence on screen?
it would seem that all your logic is in tact but I can't look to see if your notation is correct from here. In your code example here, the $$anonymous$$axEnemies isn't set to an integer. your second set of code should be in the update function if it's not already.
Sorry, I usually set $$anonymous$$axEnemies from within unity so I can increase or decrease the amount as I please. Right now, it is set to 20. The second set is also in update, in fact, it is right below the first set.
Are you sure that is your only spawning code? Perhaps you could post the rest of your Update function and one of the Spawn routines?
And I know you imply you don't, but to confirm, enemyCount isn't decremented or returned to 0 somewhere?
Sorry for all the confusion, I discovered that there was a ghost spawner that was a child of some random object in the scene. I must have accidentally dragged him there and forgot.