using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
public class PauseMenu : MonoBehaviour
{
    public GameObject pauseMenuUI;

    Gamepad pad;

    // Variable to keep track of the game's pause state
    private bool isPaused = false;
    private void Start()
    {
        if (pauseMenuUI.activeSelf)
            pauseMenuUI.SetActive(false);

    }
    void Update()
    {
        for (int i = 0; i < Gamepad.all.Count; i++)
            Gamepad.all.ElementAtOrDefault(i);


        // Check if the Escape key is pressed
        if (Input.GetKeyDown(KeyCode.Escape) || PlayerInput.c)
        {
            if (isPaused)
            {
                ResumeGame();
            }
            else
            {
                PauseGame();
            }
        }
    }

    // Method to resume the game
    public void ResumeGame()
    {
        // Hide the pause menu
        pauseMenuUI.SetActive(false);

        // Set the time scale to 1 to resume normal gameplay
        Time.timeScale = 1f;

        // Update the pause state
        isPaused = false;
    }

    // Method to pause the game
    public void PauseGame()
    {
        // Show the pause menu
        pauseMenuUI.SetActive(true);

        // Set the time scale to 0 to pause the game
        Time.timeScale = 0f;

        // Update the pause state
        isPaused = true;
    }
}