Skip to content

Instantly share code, notes, and snippets.

@MagicLike
Last active September 17, 2023 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MagicLike/d1f83cb0c4a5dd9e15899debd2aa70cf to your computer and use it in GitHub Desktop.
Save MagicLike/d1f83cb0c4a5dd9e15899debd2aa70cf to your computer and use it in GitHub Desktop.
Pause menu example in Unity (C#) - Stop using Unity!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System;
public class PauseMenu : MonoBehaviour
{
public void MainMenu()
{
SceneManager.LoadScene(0);
}
public void Restart()
{
pauseMenu.SetActive(false);
SceneManager.LoadScene(1);
time = 0f;
started = true;
}
public GameObject pauseMenu;
public void pause()
{
started = false;
pauseMenu.SetActive(true);
}
public void resume()
{
pauseMenu.SetActive(false);
started = true;
}
void Update()
{
if (started == true && Input.GetKeyDown(KeyCode.Escape))
{
pause();
} else
if (started == false && Input.GetKeyDown(KeyCode.Escape))
{
resume();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment