using UnityEngine;
using System.Collections;
public class PauseGame : MonoBehaviour
{
// Boolean used to toggle pause and play.
private bool pauseGame;
private GameObject pauseScreen;
void Start ()
{
// By default the game should not be paused.
pauseGame = false;
// Load the pause prefab into the scene.
pauseScreen = (GameObject)Instantiate(Resources.Load("PauseMenu"));
// Set the pause screen to invisible until the pause button is pressed.
pauseScreen.SetActive(false);
// Game proceeds normally when timeScale = 1.
Time.timeScale = 1;
// Disable seeing the cursor on-screen
Screen.showCursor = false;
}
void Update ()
{
if(Input.GetButtonDown("Pause"))
{
// Either pause or unpause the game.
// If the game isn't paused i.e. the player is playing, pause the game.
if(pauseGame == false)
{
pauseScreen.SetActive(true);
pauseGame = true;
Time.timeScale = 0;
Screen.showCursor = true;
}
// If game is paused and the pause button is pressed again, unpause.
else if(pauseGame == true)
{
pauseScreen.SetActive(false);
pauseGame = false;
Time.timeScale = 1;
Screen.showCursor = false;
}
}
}
}