您当前的位置: 首页 > 

Peter_Gao_

暂无认证

  • 0浏览

    0关注

    621博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

子物体任意排序SetSiblingIndex

Peter_Gao_ 发布时间:2021-09-26 14:12:29 ,浏览量:0

 如果我想运行的时候在AB两个图之间插一个图该怎么办?脚本如下所示。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

using UnityEngine;

using System.Collections;

public class UIMain : MonoBehaviour {

void Start ()

{

GameObject button = GameObject.Instantiate(Resources.Load("button"))as GameObject;

button.transform.parent = transform;

button.transform.localPosition = Vector3.zero;

button.transform.localScale = Vector3.one;

GameObject AObj = transform.Find("A").gameObject;

GameObject BObj = transform.Find("B").gameObject;

button.transform.SetSiblingIndex( AObj.transform.GetSiblingIndex() );

}

}

transform.SetSiblingIndex 和 GetSiblingIndex就是设置与获取 GameObject在兄弟节点的位置。。

设置生成物体在父节点的顺序 GameObject Line = Instantiate( Resources.Load("Prefabs/Pos1"), InsOBJ.transform );                   

Line.transform.SetSiblingIndex(0);  InsOBJ.transform 就是父节点 如果父节点下有很多东西 但是想要将 动态创建的物体放到指定的位置 用到 GmaeObject.transform.SetSiblingIndex(int); 【int是几就为第几个 默认0是第一个】  

1.SiblingIndex 从0开始依次向后增加1

2.设置 SiblingIndex 时,如果设置的索引>当前索引 ,原有索引上的元素至当前元素之下的元素一律向上移动(索引-1),就是把下面的通通上移使得目标索引位置空出,然后放入自己。

3.设置 SiblingIndex 时,如果设置的索引

关注
打赏
1664521772
查看更多评论
立即登录/注册

微信扫码登录

0.0372s