making boundry for sidescroller

hey all, im trying to make a simple script so if my player object hits the top of ther screen he stops moving up and just stays on screen at the top until he is moved down. and visa versa for the bottom. ive tried using collision on a boundry box with no luck so trying out a script, however im not sure how to go about it
thanks

btw my movement script so far is this

public class Runner : MonoBehaviour {
	
	void Update () {
		transform.Translate(5f * Time.deltaTime, 0f, 0f);

		if ( Input.GetKey(KeyCode.UpArrow) )
			transform.Translate(5f * Time.deltaTime, 20f * Time.deltaTime, 0f);

		if ( Input.GetKey(KeyCode.DownArrow) )
			transform.Translate(5f * Time.deltaTime, -20f * Time.deltaTime, 0f);

	}



}

A simple way to do it would be to clamp the transform.Y value to a min/max height;

int maxHeight = 200f;
itn minHeight = 0f;

public class Runner : MonoBehaviour {
    void Update () {
       transform.Translate(5f * Time.deltaTime, 0f, 0f);
       if ( Input.GetKey(KeyCode.UpArrow) ) {
         transform.Translate(5f * Time.deltaTime, 20f * Time.deltaTime, 0f);
		 transform.y = transform.y > maxHeight ? maxHeight : transform.y; // max height
	  }
       if ( Input.GetKey(KeyCode.DownArrow) ){
         transform.Translate(5f * Time.deltaTime, -20f * Time.deltaTime, 0f);
		 transform.y = transform.y < minHeight ? minHeight : transform.y; //min height
	   }
    }
}