Determining That The Last Of A Bunch Of Spawned Enemies Has Been Destroyed

Say you spawn a bunch of enemies. How would you determine that all the spawned enemies had been destroyed and then invoke a function telling it what to do next?

I guess the best example I can think of would be COD Zombies where after you kill the last zombie of the round the next round starts. (if your involved with games you’ve never played Call of Duty Zombies then something is wrong with you :slight_smile: here(1:12)

I know its a hard question so any help’s appreciated

Thanks

Not to worry, this is not particularly hard. :slight_smile:

If you know how many enemies you’ve spawned, and you destroy them using the Destroy function, can’t you just keep track of the number and count down?

I.e. if you spawn 20 zombies, then initialize an integer to 20. Then, every time the player kills a zombie and you have to call Destroy() on that zombie, decrement the integer by 1. Immediately afterwards, check its value. If the latest decrement caused its value to be 0, then that was the last zombie, and you will know it’s time to load the next level, or whatever you do.

Alternatively, you can keep a list of all spawned enemies active at all time, and make sure you remove enemies from it when they die. Then, you have to check its Count-property for every kill, and if the Count becomes zero, then the list is empty, meaning the recently deceased enemy was the final one.