unity中遍历Transform的子物体

1、遍历Transform直接子transform

 private void Start()
 {
      var Equipment = building.transform.FindChild("building/building/Equipment");
        foreach (Transform tran in Equipment)
        {
            Debug.LogError(tran);
        }
  }        

2、递归遍历该GameObject的所有子GameObject

 public void Awake()
    {
       Recursive(gameObject);
    }

//递归遍历该GameObject的所有子GameObject
 private static void Recursive(GameObject parenGameObject)
    {
        foreach (Transform child in parenGameObject.transform)
        {

            Recursive(child.gameObject);
            Debug.LogError(child);
        }
    }    

原文地址:https://www.cnblogs.com/Study088/p/8971280.html

时间: 2024-07-29 21:53:13

unity中遍历Transform的子物体的相关文章

unity中怎样获取全部子物体的组件

public GameObject[] obj; void Awake() { for (int i = 0; i < obj.Length; i++) { for (int j = 0; j < obj[i].transform.childCount;j++ ) { print("obj[i].transform.childCount=" + Enemy_Path[i].transform.childCount); obj[i].transform.GetChild(j)

Unity中的Transform类

childCount,第一层物体 eulerAngles,角度 Transform.hasChanged 位置,角度,缩放改变了. transform.Rotate(0, 30, 0); transform.Rotate(0,30,0,Space.World); 旋转的中心点不变,只是旋转的轴的方向可能不一样,一个按照自身坐标系,一个按照世界坐标系. 如果想让子物体绕着另外一个中心点旋转,加一个父物体,假如cube是0,0,0,想让他绕着2,2,2旋转,加一个空物体2,2,2,将cube设空物体

怎么在ZBrush中通过遮罩得到子物体

ZBrush® 中通过遮罩为模型添加子物体的方法简单且方便,我们可以通过按住Ctrl键绘制遮罩结合相关命令创建具有抽出厚度的模型提取出作为子物体附在模型表面.本文将详细介绍在Zbrush中如何通过遮罩得到子物体. 若有疑问可直接访问:http://www.zbrushcn.com/changjian/zbrush-4r7-zhezhao-ziwuti.html 1.在Light Box(灯光盒子)默认的3D工具选择PolySphere(多边形球体)物体,单击Tool>Make PolyMesh3

关于Unity中的transform组件

transform组件用途 1.维护场景树 2.对3D物体的平移,缩放,旋转 场景树 在Hierarchy视图中显示的: 一个game_scene场景,下面有Main Camera节点,Directional Light节点,game_root节点,game_root节点下又有Cube子节点,Sphere子节点,组成game_scene场景树. 1.每个节点都有一个transform组件 2.每一个继承自MonoBehaviour的组件都有一个数据成员指向这个节点的transform组件. 使用

unity中如何获取所有子物体的组件

public GameObject[] obj; void Awake() { for (int i = 0; i < obj.Length; i++) { for (int j = 0; j < obj[i].transform.childCount;j++ ) { print("obj[i].transform.childCount=" + Enemy_Path[i].transform.childCount); obj[i].transform.GetChild(j)

unity中遍历动画得到动画名字和动画数量

using UnityEngine;using System.Collections; public class AnimationsCount : MonoBehaviour { Animation anim; string[] animName; // Use this for initialization void Start () { anim = this.gameObject.GetComponent<Animation>(); int a = anim.GetClipCount(

Unity 中实用的 C# 扩展方法

Unity 内置组件基本没有可以继承的.某些比较常用但现有 API 没有定义的功能,我们可以通过 C# 的扩展类方法来实现(注意一点,扩展方法对于值类型传递的不是引用,所以无法修改原对象.并且传递体积较大的值类型可能造成性能问题).下面是一些比较实用的扩展方法,这些扩展方法的实现很多使用了 C# 的委托,关于委托可以参考这里:C# 中的 delegate, Lambda 和 event. 扩展 Transform 每一个 GameObject 都含有一个 Transform 组件(在 UGUI

ZBrush通过绘制层得到子物体方法

本文将为大家介绍在ZBrush软件中第三种创建子物体的方法,即使用绘制层得到子物体. 1.在Light Box(灯光盒子)默认的3D工具中选择SuperAverageMan_low人体模型,在视图文档中拖拽出来,进入Edit(编辑)模式,然后展开Geometry(几何体)面板,单击Divide(细分)按钮,将球体模型细分为5级. 2.单击Tool>Layers(工具>绘制层)面板中单击New(新建)按钮,创建一个新层,选择合适的笔刷和Alpha,在模型上拖拽鼠标左键,得到一个方形纹理,如下图所

ZBrush通过绘制层得到子物体

本文将为大家介绍在ZBrush? 软件中第三种创建子物体的方法,即使用绘制层得到子物体. 1.在Light Box(灯光盒子)默认的3D工具中选择SuperAverageMan_low人体模型,在视图文档中拖拽出来,进入Edit(编辑)模式,然后展开Geometry(几何体)面板,单击Divide(细分)按钮,将球体模型细分为5级. 2.单击Tool>Layers(工具>绘制层)面板中单击New(新建)按钮,创建一个新层,选择合适的笔刷和Alpha,在模型上拖拽鼠标左键,得到一个方形纹理,如下