- Home /
 
Find 1st child of root
 root
      child 1
           child 2
                child 3
 
               from a script on child 3 how do i find child 1. Note i cant use GameObject.Find("Child1") because this is a prefab thus there will be more than one instance of this.
should be:
 child1 = transform.root.transform;
 
                  from unity script reference: transform.root returns the topmost transform in the hierarchy.
thats why the addidional ".transform" is there, to get the first child
or take
 transform.root.GetChild(0);
 
                 im using it in the OnTriggerEnter function so
 child1 = col.transform.root.transform;
 
                  does not work
Answer by samz · Jul 04, 2013 at 10:17 PM
 // FINDS JOINT 2 OF THE CURRENT VINE SO YOU CAN USE IT FOR SWINGING LATER ON
 //============================================================================
             var tempHolder : Transform;
             tempHolder = col.transform.parent;
             for(var i=0; i<15; i++)
             {
                 if( tempHolder.name == "joint2" )
                 {
                     joint2 = tempHolder;
                     break;
                 }
                 else
                 {
                     tempHolder = col.transform.parent;
                 }
             }
 //============================================================================
 
              Answer by karljj1 · Jul 04, 2013 at 05:20 PM
transform.parent.parent
yes if it will always be the 3rd child that calls this.
what is i dont know how many children there will be? would need a loop for this wont i?
If you want a loop, you'd better loop the other way around from root where you can access the childCount
Your answer
 
             Follow this Question
Related Questions
Make a simple tree 1 Answer
Destroy(transform.root.gameObject ); 2 Answers
Select a child's variables from the parent. 1 Answer
Count how many parents in Hierarchy? 2 Answers
find ALL children of a parent 1 Answer