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);
    }
}
发布了9 篇原创文章 · 获赞 22 · 访问量 5735

猜你喜欢

转载自blog.csdn.net/qq_40201827/article/details/104829262
今日推荐