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

public class PauseMenu : MonoBehaviour
{
    public GameObject pauseMenu; // Reference to the pause menu UI
    public static bool isPaused; // Flag to indicate whether the game is paused

    /// <summary>
    /// Checks if the game is paused and calls the appropriate method.
    /// </summary>
    private void Update()
    {
        if (isPaused)
        {
            Pause();
        }
        else
        {
            Unpause();
        }
    }

    public void Resume()
    {
        isPaused = false;
    }

    /// <summary>
    /// Pauses the game.
    /// </summary>
    public void Pause()
    {
        pauseMenu.SetActive(true); // Show the pause menu UI
        Time.timeScale = 0f; // Pause the game time
    }

    /// <summary>
    /// Unpauses the game.
    /// </summary>
    public void Unpause()
    {
        pauseMenu.SetActive(false); // Hide the pause menu UI
        Time.timeScale = 1f; // Resume normal game time
    }


    /// <summary>
    /// Returns to the main menu.
    /// </summary>
    public void ToMenu()
    {
        isPaused = false; // Set the isPaused flag to false
        Loader.fromGame = true; // Set the loader flag to indicate returning from the game
        SceneManager.LoadScene("Loading"); // Load the main menu scene
    }

    


}
