Why can't I do a MathF.Clamp with a Input.GetAxis("Horizontal")

Newbie question:

Why will the below code work:

var move = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
transform.position += move * speed * Time.deltaTime;
float clampx = Mathf.Clamp(transform.position.x, minx, maxx);
transform.position = new Vector3(clampx, transform.position.y, 0);

But not something like this:

var move = new Vector3(Mathf.Clamp(Input.GetAxis("Horizontal"), minx, maxx), 0, 0);
transform.position += move * speed * Time.deltaTime;

Hello budy,

It’s not working because transform.position is way different than Input.GetAxis().

Get Axis will return a value between 0 and 1, and Transform.position is the object position in the game world, that’s the value that you want to clamp, that limit where/position the player can go.

Is there a way I can do the clamping in less lines that the first example? Something more elegant?