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

public class UIManager : MonoBehaviour
{
    public GameObject damageTextPrefab;
    public GameObject healthPrefab;

    public Canvas gameCanvas;

    public GameObject loseUI;
    public GameObject pauseUI;

    public Damageable damageable;

    public string menuScene;
    public string nextScene;

    private bool hasShown = false;

    private void Awake()
    {
        gameCanvas = FindAnyObjectByType<Canvas>();
    }

    private void Update()
    {
        if (!damageable.IsAlive && !hasShown)
        {
            StartCoroutine(WaitUI());
        }
    }

    public void QuiteGame()
    {
        SceneManager.LoadScene(menuScene);
    }

    public void Restart()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    public void PauseUI()
    {
        pauseUI.SetActive(true);
    }

    public void BackPauseUI()
    {
        pauseUI.SetActive(false);
    }

    IEnumerator WaitUI()
    {
        yield return new WaitForSeconds(1);
        loseUI.SetActive(true);
        hasShown = true;
    }
}
