How to get a object to stick another object?

I let a gameobject move to touch another gameobject.

And when they touch the two gameobject will be stick together.

How to do the result?

Code an OnCollisionEnter() event and simply say:
transform.parent = target.transform;