How to put two game objects together and disable rigidbody on a child?

Hi Everybody,

I need to put two game objects together when they collide. So I have a player whith the only one script attached to. Then I have many Cubes tagged “Cube”. When cube1 touches cube2 I need cube2 to become a child of cube1 with rigidbody disabled on cube2.

How do I approach it?

There is function OnCollisionEnter. On script of cube 1

void OnCollisionEnter(Collision coll) {
    GameObject cube2 = coll.gameObject

    cube2.SetParent(this.gameObject.transform);
    Destroy(cube2.GetComponent<Rigidbody>());
}