Tuesday, October 2, 2018

unity - Check if all gameobjects are destroyed


I am making a shooting game, where I have a countdown as I destroy enemies. I want to implement logic when all the game objects are destroyed within the given time, and the countdown reaches zero.



How do I do that?



Answer



You need to find a way of identifying all objects of interest. Do they have a particular script on them? You simply count them


if(GameObject.FindObjectOfType()==null)
{
// Everything destroyed
}
else
{
// Something survived

}

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...