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);
}
}