108 lines
2.4 KiB
C#
108 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.SceneManagement;
|
|
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()
|
|
{
|
|
pauseMenuUI.SetActive(isPaused);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
//for (int i = 0; i < Gamepad.all.Count; i++)
|
|
// if(Gamepad.all[i].selectButton)
|
|
|
|
|
|
|
|
if (isPaused)
|
|
{
|
|
foreach (var controller in Gamepad.all)
|
|
{
|
|
if (controller.startButton.wasReleasedThisFrame)
|
|
{
|
|
if (isPaused)
|
|
{
|
|
ResumeGame();
|
|
}
|
|
else
|
|
{
|
|
PauseGame();
|
|
}
|
|
}
|
|
if (controller.crossButton.IsPressed())
|
|
{
|
|
ResumeGame();
|
|
}
|
|
if (controller.circleButton.IsPressed())
|
|
{
|
|
QuitGame();
|
|
}
|
|
if (controller.squareButton.IsPressed())
|
|
{
|
|
MainMenu();
|
|
}
|
|
if (!isPaused)
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Check if the Escape key is pressed
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
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;
|
|
}
|
|
|
|
public void MainMenu()
|
|
{
|
|
SceneManager.LoadScene(0);
|
|
}
|
|
public void QuitGame()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|