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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM