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

public class LevelManager : MonoBehaviour
{
    [SerializeField] EventSystem eventSystem;

    [SerializeField] GameObject audioManager;
    [SerializeField] GameObject pauseScreen;
    public bool isPaused = false;
    private float timer = 0;
    [SerializeField] Text inGameTimer;

    // Start is called before the first frame update
    void Start()
    {
        pauseScreen.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        CheckInput();
        UpdateTimer();
    }

    void CheckInput()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (isPaused)
            {
                GameIsPlaying();
            }
            else
            {
                GameIsPaused();
            }
        }
    }
    public void GameIsPlaying()
    {
        Time.timeScale = 1.0f;
        isPaused = false;
        pauseScreen.SetActive(false);
        Debug.Log("play");
    }

    void GameIsPaused()
    {
        Time.timeScale = 0;
        isPaused = true;
        pauseScreen.SetActive(true);
        Debug.Log("pause");
    }

    void UpdateTimer()
    {
        if (isPaused == false)
        {
            timer += Time.deltaTime;
        }
        float times100 = timer * 100;
        float roundedTimer = Mathf.Round(times100);
        float divided100 = roundedTimer / 100;
        inGameTimer.text = divided100.ToString();
    }
}
