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?

1 Answer

1

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.