child unchild

i have a gameobject with three parts, they are all independent but i want them to be as one when they collide and assume their position as above the other but below the other one. and when i double click one part it can be dettached to the others how to do this?

If your are asking how to set an object child of another :

object1.transform.parent = object2.transform;

That will set object1 as a child of object2. To unchild :

object1.tranform.parent = null;