Answers for "unity check if object has child"

C#
2

c# unity check if gameobject has child

// 1
if(transform.childCount > 0) //do something

// 2
for (var child : Transform in transform) {
    // do whatever you want with each child transform here
}

// 3
for(var i : int = 0; i < transform.childCount; i++) {
    var child : Transform = transform[i];
    // do whatever you want with each child transform here
}

// 4
for(var something : Thing in somethingElse) {
    // do whatever you want with each something here
}

// 5
for(var i : int = 0; i < somethingElse.length; i++) {
    var something : Thing = somethingElse[i];
    // do whatever you want with each something here
}
Posted by: Guest on July-27-2021
0

unity check if child exists

Transform[] ts = GetComponentsInChildren<Transform>();
         foreach(Transform t in ts)
         {
             if(t != null)
             {
                 //do something
             }
         }
Posted by: Guest on May-10-2021

Code answers related to "unity check if object has child"

C# Answers by Framework

Browse Popular Code Answers by Language