using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;

public class PlayerTurn : MonoBehaviour
{
    public bool space;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && space)
        {
            StartCoroutine(Rotate(Vector3.up, 90, 0.07f));
            space = false;
            StartCoroutine(Cooldown());
        }
    }

    IEnumerator Rotate(Vector3 axis, float angle, float duration = 1f)
    {
        Quaternion from = transform.rotation;
        Quaternion to = transform.rotation;
        to *= Quaternion.Euler(axis * angle);

        float elapsed = 0.0f;
        while (elapsed < duration)
        {
            transform.rotation = Quaternion.Slerp(from, to, elapsed / duration);
            elapsed += Time.deltaTime;
            yield return null;
        }
        transform.rotation = to;
    }

    IEnumerator Cooldown()
    {
        //bubblegum fix for rotation
        yield return new WaitForSeconds(0.09f);
        space = true;
    }
}