- Home /
Making a Clone a Child of Another Object
I'm instantiating a girl and a dog using the following code
Instantiate (girl1, Vector3(47,177,8),rotation);
Instantiate (dog1, Vector3(47,177,2.5),rotation);
I now want the girl and dog to follow a 'ball' object as the moves, but can't work out how to use code to make the girl and dog into children of the ball.
Not sure whether I should be doing this in the same line as the Instantiation, or on a seperate line once instantiated, but either way I've tried a few things but can't work out what the code should be.
What would I need to add to the above to get the girl tofollow the 'ball'?
Can anyone help please?
Answer by spinaljack · Aug 08, 2010 at 12:07 PM
If you mean a transform child then you just do this;
var girl : GameObject = Instantiate (girl1, Vector3(47,177,8),rotation);
girl.transform.parent = ball.transform;
thanks for that. I'm still playing with it, but at the moment this is giving me the following error: "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption".
Sorry! I mistyped your answer. It does exactly what I requested. Thank you very much. Greatly appreciated.
Your answer
Follow this Question
Related Questions
Prefab clones behaviour 0 Answers
Access the renderer of a clones child object 1 Answer
Destroy One Child, Not All 2 Answers
instantiated Gameobject trying to access child of child which is a clone itself. 2 Answers
[SOLVED] How to make to clone an object and make it parent of the transform? 1 Answer