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

public class EscMenu : MonoBehaviour
{
    private InputControls inputControls;
    private InputActionMap currentActionMap;

    public GameObject canvas;
    public GameObject pauseOverlay;

    // Start is called before the first frame update
    private void Awake()
    {
        inputControls = new InputControls();
        PlayerInput playerInput = GetComponent<PlayerInput>();
        currentActionMap = playerInput.currentActionMap;
    }

    void Start()
    {
        currentActionMap.FindAction("Cancel").started += _ => Pause();
    }

    void Pause() 
    {
        int in_one = 0; 
        if (canvas.activeSelf == false) {
            Time.timeScale = 0;
            canvas.SetActive(true);
            pauseOverlay.SetActive(true);
            in_one = 1;
        }

        if (canvas.activeSelf == true && pauseOverlay.activeSelf == true && in_one==0) 
        {
            canvas.SetActive(false);
            pauseOverlay.SetActive(false);
            Time.timeScale = 1;
        }
    }
}
