-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuManager.cs
More file actions
75 lines (66 loc) · 2.02 KB
/
Copy pathMenuManager.cs
File metadata and controls
75 lines (66 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using UnityEngine;
using UnityEngine.SceneManagement; // Needed for Restarting
public class MenuManager : MonoBehaviour
{
public GameObject startMenu;
public GameObject pauseMenu;
private bool isPaused = false;
public GameObject pauseButton; // NEW: Drag your PauseButton here
public GameObject hudParent; // Drag an object containing Score and Health here
void Start()
{
// Start the game in a "Paused" state so the menu shows
Time.timeScale = 0;
startMenu.SetActive(true);
pauseMenu.SetActive(false);
// Hide the HUD at the very beginning
if (hudParent != null) hudParent.SetActive(false);
}
void Update()
{
// Check for Escape key to pause
if (Input.GetKeyDown(KeyCode.Escape) && !startMenu.activeSelf)
{
if (isPaused) ResumeGame();
else PauseGame();
}
}
public void StartGame()
{
startMenu.SetActive(false);
pauseButton.SetActive(true); // Show button when game starts
// Show the HUD when the game starts
if (hudParent != null) hudParent.SetActive(true);
Time.timeScale = 1;
}
public void PauseGame()
{
isPaused = true;
pauseMenu.SetActive(true);
pauseButton.SetActive(false); // Hide button while paused
Time.timeScale = 0;
}
public void ResumeGame()
{
isPaused = false;
pauseMenu.SetActive(false);
pauseButton.SetActive(true); // Show button when resuming
Time.timeScale = 1;
}
public void RestartGame()
{
Time.timeScale = 1;
// This reloads the current scene
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void ExitToMain()
{
// Simply reloads the scene which defaults back to the Start Menu
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void QuitGame()
{
Application.Quit();
Debug.Log("Game Exited"); // Only visible in build
}
}