码迷,mamicode.com
首页 > 编程语言 > 详细

unity, iterate immediate children and iterate all children

时间:2015-07-01 06:14:25      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

遍历所有直接子节点(immediate children):

foreach (Transform child in transform)
{
    // do whatever you want with child transform object here
}

注:transform.childCount返回的是直接子节点个数。

遍历所有子节点(包括根节点本身及所有子孙节点):

Transform[] allChildren = GetComponentsInChildren<Transform>();
foreach (Transform child in allChildren) {
    // do whatever with child transform here
}

参考:http://answers.unity3d.com/questions/10417/how-can-i-access-the-children-of-a-transform.html

unity, iterate immediate children and iterate all children

标签:

原文地址:http://www.cnblogs.com/wantnon/p/4612222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!