以下の内容はhttps://baba-s.hatenablog.com/entry/2019/11/29/140000より取得しました。


【Unity】Transform からすべての子オブジェクトを取得する方法

概要

using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    private void Awake()
    {
        var children = new List<Transform>();
        foreach ( Transform child in transform )
        {
            children.Add( child );
        }
    }
}

上記のようなスクリプトを記述することで
Transform からすべての子オブジェクトを取得できます

using System.Linq;
using UnityEngine;

public class Example : MonoBehaviour
{
    private void Awake()
    {
        var children = transform.Cast<Transform>().ToList();
    }
}

このように LINQ を使用すると一行で記述することもできます




以上の内容はhttps://baba-s.hatenablog.com/entry/2019/11/29/140000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14