How can I find child gameobject?

2020-07-02 05:12发布

I want to say somethings like..

Gameobject.find(child gameobject of specific parent Gameobject)

Can anyone help me. thanks!

5条回答
做个烂人
2楼-- · 2020-07-02 05:34

Fixing Jay Kazama's answer. The correct answers are:

  1. transform.Find ("childname")
  2. transform.FindChild ("childname")

With small t (property transform, not class Transform).

查看更多
Melony?
3楼-- · 2020-07-02 05:35

If a GameObject are you looking for in hierarchy it must be like:

transform.Find("head/eyes")
transform.FindChild("head/eyes")
查看更多
爷的心禁止访问
4楼-- · 2020-07-02 05:41

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:

  1. transform.Find("childname")
  2. transform.FindChild("childname")

The 2nd option is deprecated but still functional, so you'd better use the 1st option.

查看更多
The star\"
5楼-- · 2020-07-02 05:48

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;
查看更多
Rolldiameter
6楼-- · 2020-07-02 05:48

You can do this by GetChild(index of child members)

查看更多
登录 后发表回答