[2D] Make the movement of 2 object linked.

I’ve been searching for a solution for hours. but none of them matches my situation, object 1 also has a collider. i need to move the object 2 to object 3 using my character which is object 1.
where object 2 has a collider that can trigger another object’s(3) collider



Things I’ve assumed:

You use a key press event to grab/leave Object 2.

The collider that is used to grab items is positioned in front of the player.


Once you press the grab/leave button. You can make Object 2, child of the player object. To do that you can use:

object2.transform.SetParent (object1.transform); // and to remove:

object2.transform.SetParent (null);

To make sure that object2 is within a particular distance with the player you can use Vector2.Distance (Vector A, Vector B); and when you grab the object you can write a method that moves Object 2 to “x” distance towards the player.

X was the value that you calculated with Vector2.Distance();