How to make checkbox checked when all enemy is dead please help
How to make checkbox checked when all enemy is dead please help
Answer by tablekorner · Aug 27, 2017 at 05:00 AM
The easiest way would be to have all types of enemies in your game derived from the same class, let's call it 'Enemy'. Then you'd make sure Enemy has some kind of boolean declared, let's call it 'isDead'. Now all you'd need to do is use one of Unity's built in functions for finding Object's, 'FindObjectsOfTypeAll()'.
You'd just need to plug this loop into wherever you'd want the check to occur to see if all enemies are dead.
foreach (Enemy enemy in Resources.FindObjectsOfTypeAll<Enemy>())
{
if (enemy.isDead == true)
isAllDead = true; // public boolean to represent checked checkbox in inspector
else
isAllDead = false; // public boolean to represent checked checkbox in inspector
}
And of course make sure to declare isAllDead as a public boolean somewhere for it to show up in inspector as a checkbox.
Your answer
Follow this Question
Related Questions
My Objects disable checkbox disappeared 0 Answers
Is there a 'virtual reality supported' checkbox for iOS? Only in pro? 1 Answer
physics.checkbox 1 Answer
Physics.CheckSphere isn't working well 0 Answers
Two checkboxes with same function but they seesaw rather than changing together as desired 0 Answers