102 lines
2.2 KiB
C#
102 lines
2.2 KiB
C#
|
using System;
|
|||
|
using SHADE;
|
|||
|
using SHADE_Scripting.Audio;
|
|||
|
|
|||
|
public class PauseMenu : Script
|
|||
|
{
|
|||
|
public GameObject resumeBtn;
|
|||
|
public GameObject retryBtn;
|
|||
|
public GameObject quitBtn;
|
|||
|
|
|||
|
public GameObject gamePauseText;
|
|||
|
public GameObject canvas;
|
|||
|
|
|||
|
protected override void awake()
|
|||
|
{
|
|||
|
GameManager.Instance.GamePause = false;
|
|||
|
if (gamePauseText)
|
|||
|
gamePauseText.GetComponent<TextRenderable>().Enabled = false;
|
|||
|
if (canvas)
|
|||
|
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<UIElement>();
|
|||
|
if (resume != null)
|
|||
|
{
|
|||
|
resume.OnClick.RegisterAction(() =>
|
|||
|
{
|
|||
|
if (GameManager.Instance.GamePause)
|
|||
|
{
|
|||
|
GameManager.Instance.GamePause = false;
|
|||
|
AudioHandler.PauseAllSounds(false);
|
|||
|
if (gamePauseText)
|
|||
|
gamePauseText.GetComponent<TextRenderable>().Enabled = false;
|
|||
|
if (canvas)
|
|||
|
canvas.SetActive(false);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("Failed to register resume button.");
|
|||
|
}
|
|||
|
|
|||
|
//retry
|
|||
|
UIElement retry = retryBtn.GetComponent<UIElement>();
|
|||
|
if (retry != null)
|
|||
|
{
|
|||
|
retry.OnClick.RegisterAction(() =>
|
|||
|
{
|
|||
|
Audio.StopAllSounds();
|
|||
|
SceneManager.RestartScene();
|
|||
|
});
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("Failed to register retry button.");
|
|||
|
}
|
|||
|
|
|||
|
UIElement quit = quitBtn.GetComponent<UIElement>();
|
|||
|
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.GamePause = true;
|
|||
|
AudioHandler.PauseAllSounds(true);
|
|||
|
if (gamePauseText)
|
|||
|
gamePauseText.GetComponent<TextRenderable>().Enabled = true;
|
|||
|
if (canvas)
|
|||
|
canvas.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|