using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour
{
		private float horizontal;
		private bool hasToRotate = false;
		private bool canRotate = true;
	
	
		void Update ()
		{
				if (canRotate && Input.GetAxis ("Horizontal") > 0) {
						horizontal = 1;
						hasToRotate = true;
				}
				if (canRotate && Input.GetAxis ("Horizontal") < 0) {
						horizontal = - 1;
						hasToRotate = true;
				}
		
		}
		
		void FixedUpdate ()
		{
				if (canRotate && hasToRotate) {
						canRotate = false;
						hasToRotate = false;
			
						Debug.Log (horizontal);
						transform.rotation = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + horizontal * 90f, transform.rotation.eulerAngles.z);
						horizontal = 0;
						StartCoroutine (WaitBeforeInput ());
				}
		}
		
		IEnumerator WaitBeforeInput ()
		{
				yield return new WaitForSeconds (0.5f);
				canRotate = true;
		}
}