1 using System;
2 using
UnityEngine;
3 using
UnityEngine.UI;
4
5 public
class PauseMenu : MonoBehaviour
6 {
7     
private Toggle m_MenuToggle;
8     
private float m_TimeScaleRef = 1f;
9     
private float m_VolumeRef = 1f;
10     
private bool m_Paused;
11
12
13     
void Awake()
14     {
15         m_MenuToggle = GetComponent <Toggle> ();
16     }
17
18
19     
private void MenuOn ()
20     {
21         m_TimeScaleRef = Time.timeScale;
22         Time.timeScale =
0f;
23
24         m_VolumeRef = AudioListener.volume;
25         AudioListener.volume =
0f;
26
27         m_Paused =
true;
28     }
29
30
31     
public void MenuOff ()
32     {
33         Time.timeScale = m_TimeScaleRef;
34         AudioListener.volume = m_VolumeRef;
35         m_Paused =
false;
36     }
37
38
39     
public void OnMenuStatusChange ()
40     {
41         
if (m_MenuToggle.isOn && !m_Paused)
42         {
43             MenuOn();
44         }
45         
else if (!m_MenuToggle.isOn && m_Paused)
46         {
47             MenuOff();
48         }
49     }
50
51
52 #
if !MOBILE_INPUT
53     
void Update()
54     {
55         
if(Input.GetKeyUp(KeyCode.Escape))
56         {
57             m_MenuToggle.isOn = !m_MenuToggle.isOn;
58             Cursor.visible = m_MenuToggle.isOn;
//force the cursor visible if anythign had hidden it
59         }
60     }
61 #endif
62
63 }