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.

182244-img-20210617.png

2 Answers

2

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.

@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;