using System; using SHADE; using SHADE_Scripting.Audio; public class PauseMenu : Script { public GameObject resumeBtn; public GameObject retryBtn; public GameObject quitBtn; private TextRenderable gamePauseText; public GameObject canvas; protected override void awake() { if (GameManager.Instance != null) GameManager.Instance.GamePause = false; if (canvas) { gamePauseText = canvas.GetComponentInChildren(); canvas.SetActive(false); } if (!resumeBtn) Debug.LogError("Resume Btn missing"); if (!retryBtn) Debug.LogError("Retry Btn missing"); if (!quitBtn) Debug.LogError("Quit Btn missing"); } protected override void start() { //resume UIElement resume = resumeBtn.GetComponent(); if (resume != null) { resume.OnClick.RegisterAction(() => { if (GameManager.Instance.GamePause) { GameManager.Instance.GamePause = false; Input.SetMouseCentering(true); Application.IsCursorVisible = false; AudioHandler.PauseAllSounds(false); if (gamePauseText) gamePauseText.Enabled = false; if (canvas) canvas.SetActive(false); } }); } else { Debug.LogError("Failed to register resume button."); } //retry UIElement retry = retryBtn.GetComponent(); if (retry != null) { retry.OnClick.RegisterAction(() => { Audio.StopAllSounds(); SceneManager.RestartScene(); }); } else { Debug.LogError("Failed to register retry button."); } UIElement quit = quitBtn.GetComponent(); if (quit != null) { quit.OnClick.RegisterAction(() => { Audio.StopAllSounds(); //go to main menu SceneManager.ChangeScene(97158628); }); } else { Debug.LogError("Failed to register quit button."); } } protected override void update() { if (Input.GetKeyDown(Input.KeyCode.Escape) && !GameManager.Instance.GamePause && GameManager.Instance.stealFoodPopUpDone) { GameManager.Instance.GamePause = true; Input.SetMouseCentering(false); Application.IsCursorVisible = true; AudioHandler.PauseAllSounds(true); if (gamePauseText) gamePauseText.Enabled = true; if (canvas) canvas.SetActive(true); } } }