not allowing an object to go below a distance

hey

how would i go about not letting an object go past a local distance.

for example i have a ship that can go up, down, left and right, but i do not want it to be able to go more then 5 units in each direction.

any suggestions?

You need a referential, any empty gameObject will do the job. Set it at the center of the playable area, and whenever you want to move the player to a direction, check for the value of the Vector3, whose value is equal to player.transform.position minus referential.transform.position.

You check then for x and z values, and allow or not the move.

If player wants to move to right and player not fully to right (z < 5), then allow move.