How to get child object child gameobject?
Hii i am Abbas..
I have one doubt, how to get Child object child. i have one parent Gameobject name bed_1 that parent have four child object in that four child object one child have another 5 child how to get that 5 child ! plz replay soon as possible
Thanks in advance.
Answer by xxmariofer · Jun 17, 2021 at 07:36 AM
private GameObject GetFifthChild()
{
GameObject bed = GameObject.Find("bed_1");
foreach(Transform child in bed.transform)
{
if(child.childCount > 0)
{
return child.GetChild(0).gameObject;
}
}
return null;
}
Thanks for your answer but i am uploading runtime Gameobject i want that child when clicking that 3D model.
this code would work at runtime too. Just change the bed gameobject with your desire object
Answer by FMGtm · Jun 17, 2021 at 08:08 AM
@Abbasjahir "Thanks for your answer but i am uploading runtime Gameobject i want that child when clicking that 3D model."
There is a small language barrier between you and the community, but I think what you are trying to do is casting a ray from the mouse position, which then selects the child->child GameObject.
@FMGtm Yeah i trid using GameObject chil4 = selectedObject.transform.GetChild(3).GetChild(3).gameObject;
Your answer

Follow this Question
Related Questions
Setting localposition to a vector 3 sets everything but the x 1 Answer
Why is my Raycast parenting resetting after build? 0 Answers
Using Child Object To Control Parent 0 Answers
Gameobject transform not moving when doing animation 0 Answers
how to access the Transform of a moving child object? 1 Answer