LoginSignup
0
1

More than 1 year has passed since last update.

Unityで子要素をすべてListに入れる

Posted at
public List<GameObject> _Objects;

void Start()
{
    //子要素がある時のみ
    if (GetChild(gameObject.transform))
    {Debug.Log("取れたよ");}
}

bool GetChild(Transform _transform)
{
    if (_transform.childCount <= 0){return false;}

    for (int i = 0; i < _transform.childCount; i++)
    {
        _Objects.Add(_transform.GetChild(i).gameObject);
        GetChild(_transform.GetChild(i));
    }
    return true;
}
0
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
0
1