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