So say I have a model with a body, a head, and a nose, 3 meshes.
And the body has 4 bones.
The Hierarchy would look something like this:
So how would I destroy that Head model, and instantiate another head model in it’s place in the hierarchy?
I know I could simply just instantiate a prefab with the nose already a child of the head, but it’s the theory of destroying and instantiating meshes in and out of a hierarchies that puzzles me.
Also, is it possible to download the scripting reference anywhere? I have limited net access.
My last two posts have gone unanswered, and before that I got one incorrect answer. Seems to me like this forum is going to hell. Anyway, thanks for reading :]
Well, then you’ll want to take advantage of the transform.parent property. I do this in many of my scripts.
Suppose you wanted to replace the head. A simple sequence would be:
(1) instantiate a NewHead GameObject
(2) Setup NewHead’s parent, eg set NewHead.transform.parent = bn_Head.transform
(3) Setup NewHead’s children, eg set Nose.transform.parent = NewHead.transform
(4) finally, delete the old Head GameObject
In Unity (at least, in Unity 3 desktop and Unity 1.7 iPhone Advanced) if you click on Help | Scripting Reference you will acess the offline version (look at the URL to see exactly where it is on your systems).
It’s… fairly large, I wouldn’t recommend killing a forest to print it.
[ Edit: AzulValium beat me to it. Oh well… overanswered is better than no answers. ]
Thanks for the replies guys they’ve been really useful, it’s nice to see I’m wrong about the forum going to hell hehe
Iceshaft what method would you recommend for removing objects from the scene/hierarchy? I’m instantiating prefabs so I assumed there’d be no repercussions from destroying the instances.