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

public class PauseControl : MonoBehaviour
{
    [SerializeField] GameObject PausePanel;
    bool OnPause = false;

    CharacterController2D CC2d;

    private void Awake()
    {
        CC2d = CharacterController2D.instance.GetComponent<CharacterController2D>();
    }

    void Start()
    {
        Time.timeScale = 1.0f;
    }

    public void PressPause()
    {
        if (!OnPause)
        {
            CC2d.CanDoActions = false;
            PausePanel.SetActive(true);
            OnPause = true;
            Time.timeScale = 0f;
        }
        else
        {
            Invoke("AllowPlayerActions", 0.5f);
            PausePanel.SetActive(false);
            OnPause = false;
            Time.timeScale = 1.0f;
        }
    }


    public void Reload()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }

    public void MainMenu()
    {
        SceneManager.LoadScene("MainMenu");
    }

    private void AllowPlayerActions()
    {
        CC2d.CanDoActions = true;
    }
}
