Suggestions - All enemies Destroyed

Hi,

I did not know what to call the subject but I need some suggestions, on how to know when all enemies are destroyed? I’ll try and explain a little better:

I have a bunch of enemies that are running around, that will get destroyed by my player.
At the same time I have a bunch of enemies that are instantiated through a loop every 2 seconds, that will get destroyed by my player.

Once all enemies are destroyed a door will open.

Here’s the thing how can I find out when they are all destroyed? (to do something like open the door.)

The enemies have different tags, names etc… some are instantiated some just wait for the player to enter.

I have no idea how I would even begin to try and check if they are destroyed? Any suggestions would greatly be appreciated!!!

A quick solution would be having a int that stored how many enemies were alive, ie. when you instantiate you increment that int, every time you killed one you would decrement it, when it reaches 0 they are all dead.
Since you have enemies already on the scene that would be the starting value for the int, then you would increment and decrement as needed.
Although this doesn’t account for the detail that you might want to have ‘waves’ of enemies…hence you would need it to reach 0 and not open the door.

There’s probably some stupid flaw in my logic, but I’m a newbie I have the right to be wrong (and I spent 30 seconds thinking about this solution) :slight_smile:

hi vortex69,

lol only 30 seconds huh? I wish I was as quick :slight_smile: So Im trying it like below. I’ll let you know how the results are in a bit :smile: Really Thank You!!!

//Add the number of enemies already in the Level
static var enemyCount : int = 0; 

function Update () 
{
	
	if(enemyCount < 1)
	{
		//Instantiate prize and open door
		print("Ok Now Open The Door!"); 	
	}
	if(enemyCount > 0)
	{
		print("The Enemy Count is" + "" + enemyCount);	
	}
}

Hmm… Well Im having 2 problems

  1. You were right it says (“OK Ok Now Open The Door!”) even before the wave of enemies or until one shows up

  2. When the Enemies are Instantiated it seems to be counting 2 for each?

Oh… its counting the particle effect clone as well as the Enemy Clone because the script I have Instantiates a particle effect as well with a different prefab

I guess I’ll have to create a second script just for the particles :slight_smile: Problem 2 solved But any ideas for the door being ok to open right away before the wave starts?

Well, my ‘solution’ assumed that there would be at least one enemy alive at all time, except when the door was supposed to open.
Meaning that at the start of the whole thing there would be at least one on the map and he wouldn’t die until he had ‘backup’

There’s the stupid flaw on my logic. :slight_smile:

That wouldn’t be a bad idea except I have no idea which one the player will shoot last lol

I was also thinking If I have a few enemies already in the level that might solve it but then again there’s no saying they wont get destroyed first and that few seconds inbetween the wave of instantiated ones and our player accidently slips out the door.

I love the logic though :slight_smile: other than this I wouldn’t have a clue as to how to do it. Greatly appreciated! If something happens to come to mind please let me know.

And if anyone else has an idea no mater how crazy, Id love your input.