using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour 
{
	
	private GameObject player;
	private Animator animator;
	
	private MouseLook mouseLook;

	public static Quaternion initialRotation;

	void Awake()
	{
		player = GameObject.FindGameObjectWithTag("Player");

		animator = GetComponent<Animator> () as Animator;
		
		mouseLook = player.GetComponent<MouseLook> () as MouseLook;

		initialRotation = player.transform.rotation;
	}

	void OnTriggerEnter(Collider other)
	{
		if(other.gameObject.tag == "ghost")
		{
			player.transform.position = KeyManager.key.GetSpawnCoordinate();
		}
	}

	void Update()
	{


		//Debug.Log("MouseLook" + mouseLook.axes.ToString());

		//Debug.Log ("Rotation Asse y: " + player.transform.eulerAngles.y);

		if (player.transform.eulerAngles.y >= 315 || player.transform.eulerAngles.y <= 45) {

						Debug.Log ("Up");
						animator.SetBool("U",true);
						animator.SetBool("D",false);
						animator.SetBool("L",false);
						animator.SetBool("R",false);
			
		} else if (player.transform.eulerAngles.y <= 315 && player.transform.eulerAngles.y >= 225) {
						Debug.Log ("Left");
						animator.SetBool("U",false);
						animator.SetBool("D",false);
						animator.SetBool("L",true);
						animator.SetBool("R",false);
						
				
				} else if (player.transform.eulerAngles.y <= 225 && player.transform.eulerAngles.y >= 135) {
						Debug.Log ("Down");
			animator.SetBool("U",false);
			animator.SetBool("D",true);
			animator.SetBool("L",false);
			animator.SetBool("R",false);
			
				} else 
				{
					Debug.Log ("Right");
			animator.SetBool("U",false);
			animator.SetBool("D",false);
			animator.SetBool("L",false);
			animator.SetBool("R",true);
				}
	}
}
