using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {

    private Animator animator;
    private Quaternion rightRotation;
    private Quaternion leftRotation;
    private float timer;

	// Use this for initialization
	void Start () {
        animator = this.GetComponent<Animator>();
        leftRotation = new Quaternion(0.0f, 180.0f, 0.0f, 1.0f);
        rightRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
        timer = 0.0f;
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKey(KeyCode.A))
        {
            this.transform.rotation = leftRotation;
            animator.StopPlayback();
        }
        else if (Input.GetKey(KeyCode.D))
        {
            this.transform.rotation = rightRotation;
            animator.StopPlayback();
        }
            
        else if (!(animator.GetInteger("Direction") == 1))
            animator.StartPlayback();

        if (Input.GetKey(KeyCode.Space))
        {
            animator.SetInteger("Direction", 1);
            animator.StopPlayback();
            timer = 0.0f;
        }
        if (animator.GetInteger("Direction") == 1)
        {
            timer += Time.deltaTime;
            if (timer > 0.33f)
            {
                animator.SetInteger("Direction", 2);
            }
        }
	}

    void OnTriggerEnter(Collider other)
    {
        Debug.Log("A COLLISION HAS BEEN MADE");
        if (other.gameObject.tag == "Checkpoint")
            Debug.Log("THE COLLISION IS A CHECKPOINT");
    }

}
