-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPauseMenu.cs
54 lines (45 loc) · 1.39 KB
/
PauseMenu.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This script creates a quick pause menu, simply create an empty in your UI and parent the pause menu to it, then setup the buttons pointing to the functions of this class
public class PauseMenu : MonoBehaviour {
bool paused = false;
// Checks whether to pause or unpause
void Update () {
if (Input.GetButtonDown("Pause"))
{
if (!paused)
{
Debug.Log("paused");
Time.timeScale = 0f;
paused = true;
foreach (Transform child in transform)
{
child.gameObject.SetActive(true);
}
}
else
{
Time.timeScale = 1f;
paused = false;
foreach (Transform child in transform)
{
child.gameObject.SetActive(false);
}
}
}
}
public void Resume()//Call this function from an onClick to Resume your game from the pause menu
{
Time.timeScale = 1f;
paused = false;
foreach (Transform child in transform)
{
child.gameObject.SetActive(false);
}
}
public void Quit()//Call this function from an onClick to quit the game
{
Application.Quit();
}
}