Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Instantiating a gameObject then setting its parent during runtime

$
0
0
I have seen similar questions to this and tried them but they didnt work for me. I have a simple gui in my demo, when a button is pressed another obstacle is supposed to appear at a random position. Onscreen there are already several obstacles, these are all children of the parent "Obstacles". I would like to spawn another obstacle when the button is pressed and have it appear underneath Obstacles in the hierarchy. When i try the below code the obstacle is created however it is not a child, just a gameobject on its own. Instantiate(obstacle, randomPos, Quaternion.identity); obstacle.transform.parent = parentObstacles.transform; I have tried transform.setparent aswell, with the same results. Is there anything else I can try? I'm using Unity 5, is this the problem?

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>