LoginSignup
3
1

More than 3 years have passed since last update.

Unity ~子オブジェクトと孫オブジェクトの取得~

Posted at

使い方

  1. 親オブジェクトにアタッチします。
  2. 動作させると子と孫の名前が表示されます。

※Debug.Logを処理に変えれば子や孫を操作できます。

コード

    void Start()
    {
        foreach (Transform childTransform in this.gameObject.transform)
        {
            Debug.Log(childTransform.gameObject.name); // 子オブジェクト名を出力
            foreach (Transform grandChildTransform in childTransform)
            {
                Debug.Log(grandChildTransform.gameObject.name); // 孫オブジェクト名を出力
            }
        }
    }
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1