Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check if all children of an object are active?

I am a beginner C# coder, and I am trying to make a game in Unity. Hence the question: Can I check if all children of an object are active in a scene? I want to use it to check if all enemies are active.

like image 355
MegaRay_PL Avatar asked Oct 19 '25 13:10

MegaRay_PL


1 Answers

You could check using:

for (int i = 0; i< gameObject.transform.childCount; i++)
{
    if(!gameoObject.transform.GetChild(i).gameObject.activeInHierarchy)
    {
        return false;
    }
}
return true;

activeInHierarchy is exactly what you need.

like image 143
Johnny Avatar answered Oct 21 '25 01:10

Johnny