How do I activate collisions?

Hello, im very new to unity and I have no clue how collisions work.

I put box collider 2d’s on 3 of my objects and I have 1 object moving around, I want him to stop once it touches one of the walls, the other 2 objects.

I can do this by adding a rigidbody 2d to my moving object, but that will make it bounce left and right a small bit when I put restrictions on going down and up. How do I make it stop and not move when its hitting an object, and make it not try to still get inside the object?

Just add a line of code below the others that is something like what follows:

void OnTriggerCollision2D(Collider2D other){
if(other.tag == “Wall”) {
myRigidBody.velocity = new Vector3.zero;
}
}

To make that work you have to set the wall’s tag to something like “Wall” (Caps matter in if statements) or whatever you’d like. Then whenever they collide, they should stop moving if nothing else is setting the velocity of the object. Also, make sure you have defined a varaible at the top of your code that will represent the RigidBody2D. In this case, I named mine myRigidBody. You can do this at the top by adding something like:

private RigidBody2D myRigidBody;

Then, in the Start function, you need to set the myRigidBody to the RigidBody2D component in the object. This would look like:

myRigidBody = GetComponent();

That should work perfectly. Please let me know if you run into any problems, or if this was what you were looking for!