Unity查找自身为第几个子物体GetSiblingIndex()

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

 

posted @ 2021-07-26 13:30  剑起苍穹  阅读(1974)  评论(0编辑  收藏  举报
/*鼠标点击特效*/