Trying to keep GameObject (Ship) locked into visible screen space

Hello again!
I’m stuck on something that is driving me crazy!

I am doing a 2d side view game, with ship that I want to only to be able to travel to the edges of the screen and all space in between. When it reaches the top/bottom/sides of the screen I wish it to stop transforming in that direction so it will not travel off screen. I am using GetAxis to return the 1/-1 and with my current code my ship will move. It moves fine as long as I do not reach the edges, but when the screed edge is reached it will no longer move.

I do realize what my problem is from my code below:

//Ship movement
	float verticalMovement = Input.GetAxis("Vertical") * moveSpeed;
	
	if(ship.transform.position.y <= 6 && ship.transform.position.y >= -4){
		ship.transform.Translate(0, (verticalMovement * Time.deltaTime), 0);
	}
	float horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed;
	
	if(ship.transform.position.x <= 7.5f /*&& ship.transform.position.x >= -8.5f*/){
		ship.transform.Translate((horizontalMovement * Time.deltaTime),0,0);
	}

I’m using the if statement that checks for hard coded screen coordinates and when it reaches those coordinates it will no longer move up or down because the if statement returns a false since it reached the max coordinates and never reaches the transform line of code.

I’m not sure how to handle this since using getAxis returns the value for movement both up and down/left and right. If hardcoding the action keys I can of course do the “if” checks individually for all move directions, but do not want to hardcode these actions.

How can I check for max screen position, not move in that direction when max is reached and still move in the other directions so my ship will always remain on screen?

Instead of flat preventing the player from moving, why don’t you just cut off the bit that would move them over the edge?

if(over the bottom edge)
{
    horizontalMovement = Mathf.Clamp(horizontalMovement, 0, infinity);
}

blah blah move the ship here (outside the conditional statement)