Unity Basics - Capture a collision and make an action

I’m new in Unity, and I need to make that an object changes its position when it collides (or approaches) with another object (eg a wall). I want to make it with the appropiate script, but I’m not sure :face_with_spiral_eyes: how to do it.

I don’t know if I have to use a variable of Collision type or what.

Thanks for the help!

This is what you need to use. Unity - Scripting API: Collider.OnCollisionEnter(Collision)

From the Collision object parameter, you can get the object that collided with it using collider.gameObject.

Make sure your objects have appropriate Collider and Rigidbody components.