PauseMenu.cs
1.18 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
using System;
using UnityEngine;
using UnityEngine.UI;
public class PauseMenu : MonoBehaviour
{
private Toggle m_MenuToggle;
private float m_TimeScaleRef = 1f;
private float m_VolumeRef = 1f;
private bool m_Paused;
void Awake()
{
m_MenuToggle = GetComponent <Toggle> ();
}
private void MenuOn ()
{
m_TimeScaleRef = Time.timeScale;
Time.timeScale = 0f;
m_VolumeRef = AudioListener.volume;
AudioListener.volume = 0f;
m_Paused = true;
}
public void MenuOff ()
{
Time.timeScale = m_TimeScaleRef;
AudioListener.volume = m_VolumeRef;
m_Paused = false;
}
public void OnMenuStatusChange ()
{
if (m_MenuToggle.isOn && !m_Paused)
{
MenuOn();
}
else if (!m_MenuToggle.isOn && m_Paused)
{
MenuOff();
}
}
#if !MOBILE_INPUT
void Update()
{
if(Input.GetKeyUp(KeyCode.Escape))
{
m_MenuToggle.isOn = !m_MenuToggle.isOn;
Cursor.visible = m_MenuToggle.isOn;//force the cursor visible if anythign had hidden it
}
}
#endif
}