How to make a 2D player to stop when an obstacle appears

I am new to unity. At present working on simple 2D endless runner game like Super mario. Player’s entry state is run. I want to make player to become idle when an object like wall appears. Box collider added to object. Player Movement script as below:

It worked for me. Thank you.

set in OnCollisionEnter the bool run to false.