- Home /
Why does my pause & quit menus appear when I load next level?
When I start my game the menus work as they are supposed to. They are not visible because I have quitMenu.enabled = false; and pauseMenu.enabled = false; at void Start () in code.
It's when I start the next level that my pause menu and exit menu appear at the start of the level even though they are set to false in code. I have looked over this repeatedly and couldn't find the reason. I figure now it's time for a fresh pair of eyes to take a look.
All the functionality works with the exception of the menus appearing at the start of the next level loaded. Also when I go back to the Main Menu the menus aren't visible as they should be because they are set to false in code. I am using the same assets in both scenes with exception of the pause menu, which isn't in the starting scene, but the next scene loaded. I don't get why the code works in the starting scene but not the next scene loaded. Any sort of help would be appreciated.
Here is the code as it stands:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class menuScript : MonoBehaviour
{
public Canvas quitMenu;
public Canvas pauseMenu;
public Button startText;
public Button exitText;
// Use this for initialization
void Start ()
{
quitMenu = quitMenu.GetComponent<Canvas> ();
pauseMenu = pauseMenu.GetComponent<Canvas> ();
startText = startText.GetComponent<Button> ();
exitText = exitText.GetComponent<Button> ();
quitMenu.enabled = false;
pauseMenu.enabled = false;
}
public void ExitPress()
{
quitMenu.enabled = true;
pauseMenu.enabled = false;
startText.enabled = false;
exitText.enabled = false;
}
public void NoPress()
{
quitMenu.enabled = false;
pauseMenu.enabled = false;
startText.enabled = true;
exitText.enabled = true;
Time.timeScale = 1;//unpauses game
AudioListener.volume = 0.5f;//unmutes sound
}
public void StartLevel()
{
quitMenu.enabled = false;
pauseMenu.enabled = false;
Application.LoadLevel (1);
Time.timeScale = 1;//unpauses game
AudioListener.volume = 0.5f;//unmutes sound
}
public void MainMenu()
{
Application.LoadLevel (0);
Time.timeScale = 1;//unpauses game
AudioListener.volume = 0.5f;//unmutes sound
}
public void PauseGame()
{
pauseMenu.enabled = true;
//gameObject.pauseMenu.enabled = true;
Time.timeScale = 0;//pauses game
AudioListener.volume = 0;//mutes sound
}
public void ResumeGame()
{
pauseMenu.enabled = false;
Time.timeScale = 1;//unpauses game
AudioListener.volume = 0.5f;//unmutes sound
}
public void ExitGame()
{
Application.Quit ();
}
}