Unity_Transform.GetSiblingIndex()

来源:互联网 发布:女生网络名称大全 编辑:程序博客网 时间:2024/05/16 10:16

GetSiblingIndex获取对象在Hierarchy面板的索引值(可以用于动态修改UGUI中UI的显示效果)

using UnityEngine;using System.Collections;using System;public class Path : MonoBehaviour {    public GameObject A;    public GameObject B;    // Use this for initialization    void Start () {            int AIndex = A.transform.GetSiblingIndex();        int BIndex = B.transform.GetSiblingIndex();        Debug.Log(AIndex+"A");        Debug.Log(BIndex);        A.transform.SetSiblingIndex(BIndex);        B.transform.SetSiblingIndex(AIndex);        B.transform.parent = A.transform;       //Object.FindObjectOfType(Type type);    }    // Update is called once per frame    void Update () {    }}
using UnityEngine.UI;using UnityEngine;using System.Collections;using System;public class Path : MonoBehaviour {    public Button A;    public Button B;    // Use this for initialization    void Start () {        int AIndex = A.transform.GetSiblingIndex();        int BIndex = B.transform.GetSiblingIndex();        Debug.Log(AIndex+"A");        Debug.Log(BIndex);        A.transform.SetSiblingIndex(BIndex);        B.transform.SetSiblingIndex(AIndex);        B.transform.parent = A.transform;       //Object.FindObjectOfType(Type type);    }    // Update is called once per frame    void Update () {    }}
原创粉丝点击