如何判断一个物体下是否有子物体?getchild(0)!=null?显然不可取 那去获取拿到子物体数量?transform.GetChildCount();可以解决 但在新版本中已被弃用,可用transform.childCount来直接获取子物体数量. using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Example() { print(transform.
绑定在摄像机上的脚本 using UnityEngine; using System.Collections; public class abc : MonoBehaviour { //设置移动速度 public int speed = 5; //设置将被初始化载入的对象 public Transform newobject = null; // Use this for initialization void Start () { } // Update is called once per
在Unity3D中没有提供直接的方法获取某个GameObject的子GameObject,但是所有的GameObject都有transform对象,所以,一般是通过获取子GameObject的transform来达到遍历子GameObject的目的.官网手册中“Transform”页面给出了如下示例代码: using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Example