Answer by Kastenessen · Jul 17, 2016 at 02:04 PM
Try something like this;
for(i = 0; i < transform.childcount; i++){
if(transform.getchild(i).getcomponent()){
// then add to a list so you can access later. So make a list variable at top of code.
listname.add(transform.getchild(i).gameobject / or getcomponent for a component list.
} else{ print("null child or null component"); }
} }
Hows that?
To look for childrens children, add another Iteration for each child under the main iteration, so it iterates through each childs children and checks for the components aswell.
Hope This Helps!
But would I have to add another loop for each time I want to check for another "set of children"?
Doing it my way, yeah lol. I don't know what you are trying to make so, hard to say.
With my way you need to add another iteration for each new set of children and check if there is a new set or not so it doesn't throw an iteration error. There are other ways probably, I haven't needed to do it other ways before tho, so am unsure sorry.
I suppose use a depth integer for the amount of childrens children, and increase it in the update function to check deeper each time.
Am unsure, I haven't had to write something that automatically keeps checking deeper before.
Your answer
Follow this Question
Related Questions
Preventing A Teleporting GameObject From Passing Through Walls 2 Answers
Problem. Pick up and Grab object script, except all objects in scene are picked up instead of one. 0 Answers
Camera isn't move position? Why my camera isn't change position? 0 Answers
Looping a simple Function 3 Answers
Unity crashes when using while loop 0 Answers