-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPauseScript.cs
86 lines (76 loc) · 1.93 KB
/
PauseScript.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseScript : MonoBehaviour
{
GameObject[] pauseObjects;
AudioManager audioManager;
// Use this for initialization
void Start()
{
Time.timeScale = 1;
pauseObjects = GameObject.FindGameObjectsWithTag("PauseMenu");
hidePaused();
}
// Update is called once per frame
void Update()
{
//uses the p button to pause and unpause the game
if (Input.GetKeyDown(KeyCode.P))
{
audioManager = GameObject.Find("AudioManager").GetComponent<AudioManager>();
if (Time.timeScale == 1)
{
audioManager.SetThemeVolume(0.3f);
Time.timeScale = 0;
showPaused();
}
else if (Time.timeScale == 0)
{
audioManager.SetThemeVolume(0.7f);
Time.timeScale = 1;
hidePaused();
}
}
}
public void ExitToMainMenu()
{
SceneManager.LoadSceneAsync("Menu");
}
//Reloads the Level
public void Reload()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
//controls the pausing of the scene
public void pauseControl()
{
if (Time.timeScale == 1)
{
Time.timeScale = 0;
showPaused();
}
else if (Time.timeScale == 0)
{
Time.timeScale = 1;
hidePaused();
}
}
//shows objects with ShowOnPause tag
public void showPaused()
{
foreach (GameObject g in pauseObjects)
{
g.SetActive(true);
}
}
//hides objects with ShowOnPause tag
public void hidePaused()
{
foreach (GameObject g in pauseObjects)
{
g.SetActive(false);
}
}
}