Added pausing across all scenes and fixed any noticable bugs caused by pausing
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PauseMenu : MonoBehaviour
|
||||
{
|
||||
|
||||
public static bool GameIsPaused = false;
|
||||
|
||||
public GameObject pauseMenuUI;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(Input.GetButtonDown("Pause"))
|
||||
{
|
||||
if(GameIsPaused)
|
||||
{
|
||||
Resume();
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
} else {
|
||||
Pause();
|
||||
Cursor.visible = Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
pauseMenuUI.SetActive(false);
|
||||
Time.timeScale = 1f;
|
||||
GameIsPaused = false;
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
void Pause()
|
||||
{
|
||||
pauseMenuUI.SetActive(true);
|
||||
Time.timeScale = 0f;
|
||||
GameIsPaused = true;
|
||||
Cursor.visible = Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
public void LoadHubWorld()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
GameIsPaused = false;
|
||||
SceneManager.LoadScene("Hub World", LoadSceneMode.Single);
|
||||
Cursor.visible = !Cursor.visible;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
public void LoadMenu()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
GameIsPaused = false;
|
||||
SceneManager.LoadScene("Main Menu", LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
public void Quit()
|
||||
{
|
||||
|
||||
Application.Quit();
|
||||
Debug.Log("QUIT");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user