66 lines
1.6 KiB
C#
66 lines
1.6 KiB
C#
using UnityEngine;
|
|
|
|
public class PauseMenu : MonoBehaviour
|
|
{
|
|
[Header("UI Elemente")]
|
|
public GameObject pauseMenuUI; // Das Pausenmenü-Panel
|
|
public GameObject hudUI; // Die Lebens- und Munitionsanzeige (HUD)
|
|
|
|
public static bool GameIsPaused = false;
|
|
|
|
void Start()
|
|
{
|
|
ResumeGame();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// Überprüft, ob die ESC-Taste gedrückt wurde
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
if (GameIsPaused)
|
|
{
|
|
ResumeGame();
|
|
}
|
|
else
|
|
{
|
|
PauseGame();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PauseGame()
|
|
{
|
|
pauseMenuUI.SetActive(true); // Pausenmenü anzeigen
|
|
hudUI.SetActive(false); // Lebens- & Munitionsanzeige ausblenden
|
|
Time.timeScale = 0f; // Spielzeit anhalten
|
|
GameIsPaused = true;
|
|
|
|
// MAUSZEIGER FREIGEBEN (damit man Knöpfe drücken kann)
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
}
|
|
|
|
public void ResumeGame()
|
|
{
|
|
pauseMenuUI.SetActive(false); // Pausenmenü ausblenden
|
|
hudUI.SetActive(true); // Lebens- & Munitionsanzeige wieder anzeigen
|
|
Time.timeScale = 1f; // Spielzeit weiterlaufen lassen
|
|
GameIsPaused = false;
|
|
|
|
// MAUSZEIGER WIEDER SPERREN (fürs Gameplay)
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
Cursor.visible = false;
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
Time.timeScale = 1f;
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
}
|