本文介绍了unity将子代添加到子代中,但在顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将子对象添加到子对象的集合中,但我想确保最新的将是第一个.
I am trying to add a child object to a collection of children, but I want to make sure the the latest will be the first.
这就是我想要做的:
GameObject
- (My new object here)
- GameObject
- GameObject
- GameObject
这是我用来实例化预制件的代码:
Here is the code I am using to instantiate my prefab:
GameObject messageObj = Instantiate(storyPrefab) as GameObject;
messageObj.name = "Story";
messageObj.transform.parent = wallGrid.transform;
messageObj.transform.localScale = new Vector3(1,1,1);
希望这是有道理的.
感谢您的帮助,并在此先感谢:-)
Any help is apreciated and thanks in advance :-)
推荐答案
您可以使用 Transform.SetSiblingIndex .
因此,基本上,您希望将第一个索引设置为所需的元素:
So basically you'd want to set the first index to your desired element:
messageObj.transform.SetSiblingIndex(0);
这篇关于unity将子代添加到子代中,但在顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!