GetComponentsInChildren 不能获取enabled = false的子物体

论坛 期权论坛 脚本     
匿名网站用户   2020-12-21 03:19   18   0

Text[] txList = transform.GetComponentsInChildren<Text>();

如果事先把这些子物体都隐藏了(enabled = false),则无法获取这些子物体生成数组。

为了达到控制子物体又不能让其显示,我们可以先获取这些子物体,然后将其enabled = false;

txList = transform.GetComponentsInChildren<Text>();
foreach (var vlaue in txList)
{

//子物体隐藏
vlaue.enabled = false;
}

foreach (var vlaue in txList)
{

//子物体name打印
XM.Print("=====", vlaue.name);
}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP