How can i rotate my player using Input.GetAxis?

I am trying to make my player rotate on the y axis. I want him to be able to rotate 90 to the right when the user Input.GetAxis(“Horizontal”) > 0 and rotate 90 left when the Input.GetAxis(“Horizontal”) < 0 and to rotate to 180 when Input.GetAxis(“Vertical”) < 0.

The script im using is:

private Quaternion targetRot;

void Start ()
{
    targetRot = Quaternion.Euler (0, 0, 0);
}

void Update ()
{
    if (Input.GetAxis("Horizontal") < 0)
	{
		targetRot.y = -90;
	}
	if (Input.GetAxis("Horizontal") > 0)
	{
		targetRot.y = 90;
	}
	if (Input.GetAxis("Vertical") < 0)
	{
		targetRot.y = 180;
	}

    transform.rotation = targetRot;
}

I dont understand why this wont work. Can anyone help me? Also my next step is to make it where the player has rotation in between 90 intervals such as if the user inputs Horizontal and Vertical at the same time. Can anyone tell me how to fix this. Thank you

Quaternions are tricky and unnecessary for this use case, so I recommend using Euler angles instead. Just do the following:

  1. Change targetRot to be a Vector3 instead of a Quaternion.
  2. Delete line 5 (or set targetRot to new Vector3(0,0,0)).
  3. Change line 23 to transform.eulerAngles = targetRot;

You could also use transform.Rotate(Vector3.up) for example