How do I make a object be parented to another object using a trigger.

I have two objects. Object 1 and Object 2.
Object 1 is the player and is in front of Object 2. Object 1 can move forward. Object 1 is the main parent.
Object 2 is behind Object 1. It is not a child of Object 1. It can not move.

I’m trying to have Object 1, go through a trigger which makes Object 2 become Object 1’s child, and move.
Is there anyway to create this?

Use Unity - Scripting API: Collider.OnTriggerEnter(Collider) to detect when the trigger collision is entered (make sure Object1 has a collider & rigidbody, and Object2 has a trigger collider), then use Unity - Scripting API: Transform.SetParent to set Object2 to become Object1’s child.