Attaching GameObjects to other GameObjects

Hi all,

I want to be able to attach a game object to another when you click on the object. I am making a game involving putting pegs into slots. The peg follows the mouse and I then wish to click on the slot and attach the peg to the slot.

I am using the OnMouseDown function for the clicking the slot but cannot figure out how to attach the peg object, any suggestions?

Cheers

to make one object a child of another, set its transform.parent to the object you want to attach it to (reparents it in the scene graph). You’ll possibly want to look at setting transform.localposition/rotation/scale to 0,identity,1 respectively while you’re at it…