Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: miczec on January 26, 2015, 11:11:41 AM

Title: How to restart a level after all enemies are gone?
Post by: miczec on January 26, 2015, 11:11:41 AM
Hey there,

I'm working on a simple game, where your only objective is to shoot some enemies. What I'm trying to accomplish is a way to restart the level after all enemies are dead. I tried using "Game Object Is Null", which works perfectly fine if you only have one enemy in the scene. In my case, there are several bad guys to kill... So I asked myself if it is possible to tell playmaker to look if there are any gameobjects tagged as enemy - and if there's no one left, to just restart the level.

Would be great if anyone has a solution.

Thanks,
Mike.
Title: Re: How to restart a level after all enemies are gone?
Post by: Lane on January 26, 2015, 11:12:52 AM
If you know the number of enemies that are spawned then you can just subtract 1 from that total every time an enemy dies and when the number reaches zero then all of the enemies are dead and you can end the level.
Title: Re: How to restart a level after all enemies are gone?
Post by: miczec on January 26, 2015, 11:19:40 AM
If you know the number of enemies that are spawned then you can just subtract 1 from that total every time an enemy dies and when the number reaches zero then all of the enemies are dead and you can end the level.

hey lane, thank you!

i'm kind of stuck in my thinking process right now. so currently, i've set up a empty game object with the following fsm:

State 1: Game object is Null
State 2: Restart Level

so how exactly could i add the subtraction part to this?

sorry, i'm still very new to all this...
Title: Re: How to restart a level after all enemies are gone?
Post by: Lane on January 26, 2015, 11:28:39 AM
Use a global variable with the total count of the enemies in the level. If you spawn an enemy then add 1 to that count. If an enemy dies, subtract 1 from that number...

This is maintaining a number of the current amount of enemies in the level. Now all you have to do is an Int Compare to 0 and fire and event to a state which ends the level.
Title: Re: How to restart a level after all enemies are gone?
Post by: miczec on January 26, 2015, 12:08:12 PM
thanks!

your advice pushed me in the right direction! i found the best solution is to use the "get tag count" action and simply compare it to 0.