How to manage instantiated assembly files at run time as children

I have a game in Unity where I create GameObjects every few seconds. Then, in the hierarchy, prefabricated files are displayed in the list of their instances, for example:

EnemyBlue(Clone)
EnemyRed(Clone)
EnemyGreen(Clone)
EnemyBlue(Clone)

What clogs my hierarchy. My question is, is it possible to instantiate GameObjects as a child of an empty GameObject, for example:

Enemies // An Empty GameObject
    EnemyBlue(Clone)
    EnemyRed(Clone)
    EnemyGreen(Clone)
    EnemyBlue(Clone)
+4
source share
2 answers

You can set the parent of the transform like the ILiveForVR mentioned, but you can also set the parent for the existing one:

gameObject.transform.parent = GameObject.Find("Name of game object").transform;

+4
source

: http://docs.unity3d.com/ScriptReference/Transform.SetParent.html

- : EnemyBlue.tranform.SetParent(Enemies.transform);

+2

Source: https://habr.com/ru/post/1612579/


All Articles