How to attach two gameObjects together programmatically?

I have two Game Objects that are moving. When their colliders make contact, as indicated by OnTriggerEnter, I stop changing the position of GameObject1, and make it a child of GameObject2:

GameObject1.transform.parent = GameObject2.transform;

GameObject2 is still being moved using

GameObject2.transform.Translate(moveVector);

But what happens is that both objects stop moving and Unity hangs. Can anyone tell me the correct way to attach two game objects and move one of the game objects and the other game object moves in the same manner as the first game object?

[FIXED] - Bug in my code caused Unity to hang. The parent approach above works fine.

could you paste the entire script please? :slight_smile: