zoukankan      html  css  js  c++  java
  • Unity中获取物体的子物体

    如果想获取一级子节点

    1  foreach (Transform child in this.transform)
    2         {
    3             Debug.Log(child.name);
    4         }
    View Code

    如果想获取所有子节点

    1  foreach (Transform child in gameObject.GetComponentsInChildren<Transform>())
    2         {
    3             Debug.Log(child.name);
    4         }
    View Code

    这样会包括所有带有transform属性的子节点。

    在unityAPI中也有介绍

    1 public class ExampleClass : MonoBehaviour {
    2     void Example() {
    3         foreach (Transform child in transform) {
    4             child.position += Vector3.up * 10.0F;
    5         }
    6     }
    7 }
    View Code

    欢迎广大unity兴趣爱好者加群学习165628892 (进群备注:博客)  随时提出问题解决问题!

    树欲静而风不止,子欲养而亲不待。

    2016年12月8日15:12:38

  • 相关阅读:
    3.22
    练习 3.16
    简单工厂模式
    Java-不可变字符串
    java中的缓冲流
    TCP协议下java通信
    nginx优化
    nginx反向代理
    shell-for循环
    shell-数组
  • 原文地址:https://www.cnblogs.com/unityzc/p/6145037.html
Copyright © 2011-2022 走看看