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

public class GameOver : MonoBehaviour
{
	[SerializeField]
	private Image blackPanel;
	[SerializeField]
	private Text gameOverText, scoreText, pressAnyKey;

	[SerializeField]
	private Score score;

	void Awake()
	{
		blackPanel.CrossFadeAlpha(0, 0, true);
		gameOverText.CrossFadeAlpha(0, 0, true);
		scoreText.CrossFadeAlpha(0, 0, true);
		pressAnyKey.CrossFadeAlpha(0, 0, true);
	}

	public void EndGame()
	{
		StartCoroutine(GameOverAnim());
	}

	IEnumerator GameOverAnim()
	{
		blackPanel.CrossFadeAlpha(1, 1.5f, true);

		yield return new WaitForSeconds(1.5f);

		scoreText.text = "Score: " + score.ScoreValue.ToString();

		gameOverText.CrossFadeAlpha(1, 1, true);
		scoreText.CrossFadeAlpha(1, 1, true);

		yield return new WaitForSeconds(1);

		pressAnyKey.CrossFadeAlpha(1, 1, true);

		while(!Input.anyKey)
		{
			yield return null;
		}

		SceneManager.LoadScene(0);
	}
}
