首页 > 技术文章 > Unity查找自身为第几个子物体GetSiblingIndex()

qq2351194611 2021-07-26 13:30 原文

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

 

推荐阅读