2024-02-04 10:24:51 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
2024-02-04 11:39:08 +01:00
|
|
|
using UnityEngine.SceneManagement;
|
2024-02-04 10:24:51 +01:00
|
|
|
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()
|
|
|
|
{
|
2024-02-04 16:32:14 +01:00
|
|
|
pauseMenuUI.SetActive(isPaused);
|
2024-02-04 10:24:51 +01:00
|
|
|
}
|
2024-02-04 16:32:14 +01:00
|
|
|
|
2024-02-04 10:24:51 +01:00
|
|
|
void Update()
|
|
|
|
{
|
2024-02-04 10:29:51 +01:00
|
|
|
//for (int i = 0; i < Gamepad.all.Count; i++)
|
2024-02-04 11:52:16 +01:00
|
|
|
// if(Gamepad.all[i].selectButton)
|
2024-02-04 10:24:51 +01:00
|
|
|
|
|
|
|
|
2024-02-04 16:55:37 +01:00
|
|
|
|
|
|
|
if (isPaused)
|
2024-02-04 11:52:16 +01:00
|
|
|
{
|
2024-02-04 16:55:37 +01:00
|
|
|
foreach (var controller in Gamepad.all)
|
2024-02-04 11:52:16 +01:00
|
|
|
{
|
2024-02-04 16:55:37 +01:00
|
|
|
if (controller.startButton.wasReleasedThisFrame)
|
|
|
|
{
|
|
|
|
if (isPaused)
|
|
|
|
{
|
|
|
|
ResumeGame();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PauseGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (controller.crossButton.IsPressed())
|
2024-02-04 11:52:16 +01:00
|
|
|
{
|
|
|
|
ResumeGame();
|
|
|
|
}
|
2024-02-04 16:55:37 +01:00
|
|
|
if (controller.circleButton.IsPressed())
|
2024-02-04 11:52:16 +01:00
|
|
|
{
|
2024-02-04 16:55:37 +01:00
|
|
|
QuitGame();
|
|
|
|
}
|
|
|
|
if (controller.squareButton.IsPressed())
|
|
|
|
{
|
|
|
|
MainMenu();
|
2024-02-04 11:52:16 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-04 23:18:40 +01:00
|
|
|
if (!isPaused)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (controller.crossButton.IsPressed())
|
|
|
|
{
|
|
|
|
ResumeGame();
|
|
|
|
}
|
|
|
|
if (controller.circleButton.IsPressed())
|
|
|
|
{
|
|
|
|
QuitGame();
|
|
|
|
}
|
|
|
|
if (controller.squareButton.IsPressed())
|
|
|
|
{
|
|
|
|
MainMenu();
|
|
|
|
}
|
2024-02-04 11:52:16 +01:00
|
|
|
}
|
|
|
|
|
2024-02-04 10:24:51 +01:00
|
|
|
// Check if the Escape key is pressed
|
2024-02-04 10:29:51 +01:00
|
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
2024-02-04 10:24:51 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2024-02-04 11:39:08 +01:00
|
|
|
|
|
|
|
public void MainMenu()
|
|
|
|
{
|
2024-02-04 23:18:40 +01:00
|
|
|
SceneManager.LoadScene(0);
|
2024-02-04 11:39:08 +01:00
|
|
|
}
|
|
|
|
public void QuitGame()
|
|
|
|
{
|
|
|
|
Application.Quit();
|
|
|
|
}
|
2024-02-04 10:24:51 +01:00
|
|
|
}
|