unity3d - Unity: Prefab parenting in code -


let's want multiple prefab object called childtile, parenting single prefab object called parenttile. whenever parenttile rotates, childtiles rotated around parenttile.

basically wrote:

public gameobject childprefab; public gameobject parentprefab;  void update() {    for(int = 0; < 10; i++)    {       gameobject clone = instantiate(childprefab, /*psuedocode: random position*/ , quaternion.identity)        clone.transform.parent = parentprefab;     } } 

the expected result during runtime, if rotate parentprefab @ scene, 10 childprefabs should rotate. i've tried many ways failed, unless manually drag childprefabs parentprefab on hierachy bar.

are sure want instantiate 10 child prefabs on each frame (update called once per frame).

i think problem is, did not instantiate parent prefab.

if take code, , fix it, works charm me.

public gameobject childprefab; public gameobject parentprefab;  void start()  {     gameobject parent = instantiate(parentprefab) gameobject;      for(int = 0; < 10; i++)     {         gameobject child = instantiate(childprefab) gameobject;         child.transform.parent = parent.transform;     } } 

this result of above code, , suspect, that's want?

enter image description here


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -