So I am programming a pause menu and everything is running smoothly, however when I click back while in the SettingsCanvas or CreditsCanvas my pause menu disappears like when you click Escape again. I know that the cause is the way I have the code setup for handling opening and closing the Pause Menu. I am just not sure how to go about fixing the problem, as I would like to keep the canvas method of sub menus.
Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Pause : MonoBehaviour {
#region Variables
public GameObject CreditsCan;
public GameObject PauseCan;
public GameObject SettingsCan;
public string[] credits =
{
"AERO",
"Programming by Stormy Wentworth",
"Music by Cody Parsons",
"Copyright (c) 2017 AERO Studios"
};
#endregion
#region Unity Functions
private void Start()
{
StartingCanvas();
}
private void Update()
{
EscapePressed();
}
#endregion
#region Functions
public void BackToMenuClicked()
{
SceneManager.LoadScene("MainMenu");
}
public void CreditsClicked()
{
PauseCan.SetActive(false);
CreditsCan.SetActive(true);
SettingsCan.SetActive(false);
}
public void EscapePressed()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (PauseCan.activeInHierarchy == false)
{
PauseCan.SetActive(true);
Time.timeScale = 0.2f;
}
else if (PauseCan.activeInHierarchy == true)
{
PauseCan.SetActive(false);
Time.timeScale = 1.0f;
}
}
}
public void StartingCanvas()
{
PauseCan.SetActive(false);
CreditsCan.SetActive(false);
SettingsCan.SetActive(false);
}
public void SettingsClicked()
{
PauseCan.SetActive(false);
CreditsCan.SetActive(false);
SettingsCan.SetActive(true);
}
public void QuitClicked()
{
Application.Quit();
}
#endregion
}
Any help is appreciated.