我如何抓住所有子gameobjects? [英] How do I grab all sub gameobjects?

查看:155
本文介绍了我如何抓住所有子gameobjects?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让所有的子gameobjects?我试图 GameObject.Find ,但需要的名称字符串

Is there a way to get all sub gameobjects? I was trying GameObject.Find but that needs the name as string.

推荐答案

您可以找到你的所有子GameObjects是这样的:

You can find all your child GameObjects like this:

请列表,告诉团结类型为游戏对象

Make a list, tell Unity the type is GameObject.

List<GameObject> list = new List<GameObject>(); 



然后遍历父游戏对象的使用变换的foreach 循环。请注意,在我们正在采取的一个事实,即变换的优点的码具有游戏物体组件。

Then traverse the transform of the parent GameObject using a foreach loop. Note that in the code we are taking advantage of the fact that Transform has a gameObject component.

foreach(Transform t in transform)
    list.Add(t.gameObject);

这篇关于我如何抓住所有子gameobjects?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆