Unity2019.3API教程(六)Transform.childCount

childCount:The number of children the parent Transform has.
语法:public int childCount;
该属性表示查看当前物体子物体数量,可用于判断物体下是否含有子物体,在老版本中用transform.GetChildCount()方法进行获取,但是该方法已经弃用,于是childCount属性应势而生,演示如下:

using UnityEngine;

public class childCountTest : MonoBehaviour
{
    void Start()
    {
        GameObject go = new GameObject();
        Debug.Log(go.transform.childCount);
    }
}

你可能感兴趣的:(Unity,API,游戏开发,unity3d)