How to find child of a GameObject or the script attached to child GameObject via script

后端 未结 3 2058
时光说笑
时光说笑 2020-12-03 15:05

I know this is a bit of a stupid question, but how would I reference the child (a cube) of a game object via script(the script is attached to the gameObject). (the equivalen

3条回答
  •  [愿得一人]
    2020-12-03 15:36

    You could have public variable in parent gameObject.

    public Tranform childGameObject;

    and then assign your child gameObject to it.

    This way you avoid hidden dependencies. As well as your child cube can be inside of another parent and another parent.

提交回复
热议问题