1.API GetSiblingIndex(); Gets the sibling index
直接掛到 四個按鈕上 即可看到每一個按鈕的索引 (也就是Canvas下面有幾個子物體 索引從0開始)
代碼:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class GetChild_ID : MonoBehaviour { public int IDD; public Transform parent; // Start is called before the first frame update void Start() { parent = this.transform.parent; IDD = this.transform.GetSiblingIndex(); } }