Skip to content

Instantly share code, notes, and snippets.

@RoeiRubach
Last active May 17, 2020 14:55
Show Gist options
  • Select an option

  • Save RoeiRubach/90d44211b9820a66bbe4e4d09e19f44e to your computer and use it in GitHub Desktop.

Select an option

Save RoeiRubach/90d44211b9820a66bbe4e4d09e19f44e to your computer and use it in GitHub Desktop.
[Pause Menu] Pause menu controller #PauseMenu
using UnityEngine;
public class PauseMenuController : MonoBehaviour
{
public static bool IsGamePaused = false;
[SerializeField] private GameObject _onGameUI;
[SerializeField] private GameObject _pauseMenuUI;
[SerializeField] private GameObject _optionsMenuUI;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (IsGamePaused)
ResumeGame();
else
PauseGame();
}
}
public void ResumeGame()
{
_pauseMenuUI.SetActive(false);
_onGameUI.SetActive(true);
Time.timeScale = 1f;
IsGamePaused = false;
}
public void PauseGame()
{
_onGameUI.SetActive(false);
_pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
IsGamePaused = true;
}
public void EnterOptionsMenu()
{
_pauseMenuUI.SetActive(false);
_optionsMenuUI.SetActive(true);
}
public void ExitGame()
{
Application.Quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment