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);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章