简体   繁体   English

如何在[InitializeOnLoad]脚本类型中更改GameObjects在层次结构上的位置?

[英]How can I change GameObjects location on the Hierarchy in [InitializeOnLoad] script type?

I mean that if in the Hierarchy I have some objects that are children this specific objects to move them to the main root. 我的意思是,如果在层次结构中,我有一些对象是子对象,则此特定对象会将它们移到主根。

For example let's say I have this Hierarchy tree: 例如,假设我有此层次结构树:

Cube1
 Cube1
 Cube1
 Cube1
  Cube1
Cube2
 Cube3

The first Cube1 and the Cube2 are in the main root. 第一个Cube1和Cube2在主根目录中。 Now I want to move the 3 childs of the main Cube1 and Cube3 to the main root: 现在,我想将主Cube1和Cube3的3个子级移动到主根目录:

Cube1
 Cube1
Cube1
Cube1
Cube1
Cube2
Cube3

The main goal is to move some specific objects from being children to the main root in the hierarchy. 主要目标是将某些特定对象从子级移到层次结构的主根。 Like when I'm dragging a gameobject to the main scene root to do it by script. 就像我将游戏对象拖到主场景根以通过脚本进行操作时一样。

如果我理解正确,那么您正在寻找的是:

transform.SetParent(null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何只添加一次[InitializeOnLoad]脚本中的列表? - How can I add to a List in [InitializeOnLoad] script only once? 如何根据层次结构中的场景顺序对循环进行排序以 debug.log 游戏对象? - How can I sort the loop to debug.log the gameobjects according to the scenes order in the hierarchy? 通过InitializeOnLoad从编辑器实例化GameObjects - Instantiate GameObjects from editor via InitializeOnLoad 在InitializeOnLoad上更改GameObject组件 - Change GameObject Component on InitializeOnLoad 如何检查脚本附加到的游戏对象以便在多个游戏对象上使用相同的脚本? - How can I check the gameobject that the script is attached to in order to use the same script on multiple gameobjects? 如何让所有游戏对象检查哪些游戏对象有碰撞器,哪些游戏对象根本没有碰撞器? - How can I get all gameobjects to check what gameobjects have colliders and what colliders and what gameobjects dont have colliders at all? 如何统一更改游戏对象的颜色? - How to change the colors of gameobjects in unity? 如何通过脚本在Unity中选择层次结构中的对象? - How can I select object in hierarchy in Unity via script? 如何检测有多少游戏对象拥有某种材质? - How can I detect how many gameobjects have a certain material? 如何在游戏对象之间添加相等的距离? - How can I add equal gap between gameobjects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM