using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour
{

    public static bool isPaused = false;

    public GameObject pauseMenu;

    void Update()
    {

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (isPaused)
            {
                Resume();
            } else
            {
                Paused();
            }
        }

    }

    
    void Paused()
    {
        //stopper les mouvements du perso
        MoveCharacter.instance.enabled = false;
        //affiche menu pause
        pauseMenu.SetActive(true);

        //met en pause le jeu
        Time.timeScale = 0;
        isPaused = true;

    }

    public void Resume()
    {
        
        MoveCharacter.instance.enabled = true;
       
        //affiche menu pause
        pauseMenu.SetActive(false);

        //met en pause le jeu
        Time.timeScale = 1;
        isPaused = false;

    }

    public void MainMenu()
    {
        DontDestroyOnLoadScene.instance.RemoveFromDontDestroyOnLoad();
        Resume();
        SceneManager.LoadScene("MainMenu");
    }

}
