how to control "Input.GetAxis"

Hi! I use the following code to move the object:
RB.velocity = new Vector2(Input.GetAxis("Vertical") * 4f, RB.velocity.y); in FixedUpdate()
please tell me how to limit the movement of an object by condition. The fact is that when I use an if, for example: if (Input.GetKey(KeyCode.A)) { RB.velocity = new Vector2(Input.GetAxis("Horizontal") * 6f, RB.velocity.x); }

the object starts to move diagonally, not horizontaly.

That’s because you’re using RB.velocity.x in you new Vector2. Instead make it 0f.
You can also remove the if statement completely.

Something like this should be fine

RB.velocity = new Vector2(Input.GetAxis("Horizontal") * 6f, 0);

You could also use this to enable it to move vertically aswell

RB.velocity = new Vector2(Input.GetAxis("Horizontal") * 6f, Input.GetAxis("Vertical") * 6f);

Or forwards/backwards

 RB.velocity = new Vector3(Input.GetAxis("Horizontal") * 6f, 0f, Input.GetAxis("Vertical") * 6f);

thanks a lot!