C# - How to vary rotation speed according to movement speed

Hi, I’m currently in the process of making a top down shooter and need to get the player to rotate fast when running and slowly when walking. I have The following code but I just don’t see why it is that it’s not working:

using UnityEngine;
using System.Collections;

[RequireComponent (typeof (CharacterController))]
public class PlayerController : MonoBehaviour 
{
	//Player Properties
	public float rotationSpeedRun = 5000;
	public float rotationSpeedWalk = 450;
	public float walkSpeed = 5;
	public float runSpeed = 8;

	private Quaternion targetRotation;
	private CharacterController controller;

	// Use this for initialization
	void Start () 
	{
		controller = GetComponent<CharacterController> ();
	}
	
	// Update is called once per frame
	void Update () 
	{
		Vector3 input = new Vector3(Input.GetAxisRaw("Horizontal"),0,Input.GetAxisRaw("Vertical"));

		if (input != Vector3.zero) 
		{
			targetRotation = Quaternion.LookRotation (input);
			transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeedWalk * Time.deltaTime);
		} 

		else if (Input.GetButton ("Run")&&(input != Vector3.zero))
		{
			targetRotation = Quaternion.LookRotation (input);
			transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeedRun * Time.deltaTime);
		}

		Vector3 motion = input;
		motion *= (Mathf.Abs (input.x) == 1 && Mathf.Abs (input.x) == 1) ? .7f : 1;
		motion *= (Input.GetButton ("Run")) ? runSpeed : walkSpeed;
		motion += Vector3.up * -8;

		controller.Move (motion * Time.deltaTime);
	}
}

All I get is the player always rotating at the slower speed even when running.

I bet it’s the simplest thing so a second pair of eyes to read over my player controller script would be awesome. Thanks!

You’ve done this:

if (input != Vector3.zero) {
    ...
}
else if (Input.GetButton ("Run") && (input != Vector3.zero)) {
    ...
}

The else-if can never run, as if the input is not equal to zero, the if would run, and the else would never be evaluated.

I think the best way to restructure would be:

if (input != Vector3.zero) {
    targetRotation = Quaternion.LookRotation (input);

    if(Input.GetButton ("Run"))
        transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeedRun * Time.deltaTime);
    else
        transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeedWalk * Time.deltaTime);
}