Restricting movement along an axis

Veyr new to Unity, and trying to get the ball rolling.

Follows a few tutorials, and now i’m stuck as id’ like to get my player to be restricted within a boundary on the axis.

this is my player movement code…

amtToMove = playerSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;

transform.Translate(Vector3.right * amtToMove);

However I haven’t a clue where to go from here.

Any help, redirects would be most appreciated

If you want to limit the X range within which the player is allowed to move, take a look at the position element of the player’s transform, and use Mathf.Clamp() to restrict it to that range.

i googled “Mathf.Clamp”

and i got some example code, tweeked and it workied. Thank you!