- Home /
Changing the hierarchy through code
I am making a game and am coding it in javascript. During gameplay I add An object to the hierachy through code.
I was wondering if it was possible so that when this object gets added it would be added to a group???
I think because I am using a prefab it has an issue. A couple of the other sites I looked at said prefabs can be an issue.
This is the line I used to create the object
var player = Instantiate(playerPrefab, GameObject.Find("CreatePlayer").transform.position, Quaternion.identity);
Which is what I got from this site. This will create the player, but on another object I have all the code to make the player move around. So that is why I want to add the newly created object to the object with all the code.
Could the fact it is a prefab be an issue???
Thanks
sure. you're looking for .parent ... it's part of TRANSFOR$$anonymous$$ ... NOT anything else (that often catches people out)
http://docs.unity3d.com/Documentation/ScriptReference/Transform-parent.html
changing the parent of something during gameplay is really central to program$$anonymous$$g video games, it's how you "stick" something to something else and so on. it is also critical for doing calculations, etc
hope it helps
Fattie, I already had a look at this, but thank you very much for your help.
I think because I am using a prefab it has an issue. A couple of the other sites I looked at said prefabs can be an issue.
This is the line I used to create the object
var player = Instantiate(playerPrefab, GameObject.Find("CreatePlayer").transform.position, Quaternion.identity);
Which is what I got from this site. This will create the player, but on another object I have all the code to make the player move around. So that is why I want to add the newly created object to the object with all the code.
Coulld the fact it is prefab be an issue???
Sorry Fattie, just reread that site you sent me to look at and I understood it a bit better. Thank you so much It is working now.
Thank you again
Your answer
Follow this Question
Related Questions
Particle System playing spontaneously 1 Answer
Unity hierarchy not loading and flashes around. 0 Answers
NavMesh and WaveSpawner dont work together! 2 Answers
Hierarchy question 1 Answer