Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- public class pause : MonoBehaviour
- {
- bool paused = false;
- void Update()
- {
- if(Input.GetButtonDown("escape"))
- paused = togglePause();
- }
- void OnGUI()
- {
- if(paused)
- {
- GUILayout.Label("Game is paused!");
- if(GUILayout.Button("Click me to unpause"))
- paused = togglePause();
- }
- }
- bool togglePause()
- {
- if(Time.timeScale == 0f)
- {
- Time.timeScale = 1f;
- return(false);
- }
- else
- {
- Time.timeScale = 0f;
- return(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement