using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {
	public GameObject character;
	public float speed = 4.5f;
	private float dirspeed = 40.0f;
	private bool waving = false;
	private float wavetimer = 40;
	Animator anim;


	// Update is called once per frame
	void Start(){
		anim = GetComponent<Animator> ();

	}
	void Update () {
		anim.SetFloat ("speed", speed);
		anim.SetBool ("waving", waving);
		if (Input.GetKey (KeyCode.RightArrow)) {
			transform.Rotate(Vector3.up * dirspeed * Time.deltaTime);
		}
		if (Input.GetKey (KeyCode.LeftArrow)) {
			transform.Rotate(Vector3.down * dirspeed * Time.deltaTime);
		}
		if (Input.GetKey (KeyCode.UpArrow)) {
			transform.position += transform.forward * speed * Time.deltaTime;
		}
		if (Input.GetKey (KeyCode.DownArrow)) {
			transform.position -= transform.forward * speed * Time.deltaTime;
		}
		if (!Input.GetKey (KeyCode.DownArrow) && !Input.GetKey (KeyCode.UpArrow)) {
			speed = 0f;
		} else { 
			speed = 20f;
		}
		if (!Input.GetKey (KeyCode.LeftArrow) && !Input.GetKey (KeyCode.RightArrow)) {
			dirspeed = 0f;
		} else { 
			dirspeed = 80.0f;
		}
		if (Input.GetKeyDown (KeyCode.Space)) {
			waving = true;
		}
		if(waving == true){
			speed = 0;
			wavetimer--;
	}
		if(wavetimer <=0){
			waving = false;
			wavetimer = 40;
		}
}
}
