Stop movement when at walls

I need help making a script to make my object stop when it hits the walls, but u would still be able to move in the opposite directions. Im sorry for the noob question i just started with unity a few days ago.

If you use a CharacterController to move your objects they will stop at walls (if they have colliders attached) automatically.