Reputation:
I want to say somethings like..
Gameobject.find(child gameobject of specific parent Gameobject)
Can anyone help me. thanks!
Upvotes: 30
Views: 126658
Reputation: 4306
For answers above stating transform.FindChild("childname")
as Answer, this is to inform you that transform.FindChild("childname")
is deprecated.
Use this, this will work as expected
transform.Find("childName");
if you want to find Child of a GameObject by name, use this,
GameObject head = HeadPanel; // just for reference
head.transorm.Find("childName").gameObject;
Upvotes: 5
Reputation: 81
If a GameObject are you looking for in hierarchy it must be like:
transform.Find("head/eyes")
transform.FindChild("head/eyes")
Upvotes: 8
Reputation: 3277
GameObject.Find
will search for a gameobject in the scene. To search a gameobject from a parent, use Transform
.
There are 2 ways of doing it:
transform.Find("childname")
transform.FindChild("childname")
The 2nd option is deprecated but still functional, so you'd better use the 1st option.
Upvotes: 62
Reputation: 155
Fixing Jay Kazama's answer. The correct answers are:
With small t (property transform, not class Transform).
Upvotes: 5