C# Pause Menu Buttons not working in only 1 scene
Hi all, "semi new" to Unity and C#... let me just say that I went through about 60 different answer pages to try and find an answer before writing here! I also searched all over google for hours! (not kidding)
I have a very basic pause menu that I load in my 1st scene, which brings me immediately to my "hub scene", from there the menu works perfectly... i can load level 1 and 2 with no problems and the menu keep working as intented (I can change volume, go back to hub, quit application or resume)... everything works in hub AND level 1 and 2...
However, when loading level 3 which is a 2d space shooter (see unity tutorial space shooter as its very similar), the menu BUTTONS stops working... I can press ESC to open it... audio gets "dimmed"... mouse appears... I can close the menu again with ESC and game resumes perfectly... however none of the buttons on the menu works! Audio slider doesnt respond... and neither does any of the 3 buttons (quit, resume, return hub)... My "GUESS" is that since that scene has 1 coroutine with some yield and wait for second that could block the menu... i tried pretty much breaking that scene and removing as much as i could but nothing worked... menu doesnt want to work in that 1 scene...
Here is the full code from my pause menu (however i have re-written it 3 times with different syntax and sub functions and nothing changed) menu works in hub and in stage 1 and 2 but not in 3rd one...
THANKS to anyone who read this and many more thanks if you can help me out! :)
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using UnityEngine.UI;
using UnityEngine.Audio;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityStandardAssets.Characters.FirstPerson
{
[RequireComponent(typeof (CharacterController))]
public class PauseManager : MonoBehaviour {
public AudioMixerSnapshot paused;
public AudioMixerSnapshot unpaused;
[SerializeField] private MouseLook m_MouseLook;
Canvas canvas;
void Start()
{
SceneManager.LoadScene("HugoArcade");
canvas = GetComponent<Canvas>();
canvas.enabled = !canvas.enabled;
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.Escape) && Time.timeScale == 1)
{
canvas.enabled = true;
m_MouseLook.SetCursorLock(false);
paused.TransitionTo(.01f);
Time.timeScale = 0;
}
else if (Input.GetKeyDown (KeyCode.Escape) && Time.timeScale == 0)
{
canvas.enabled = false;
m_MouseLook.SetCursorLock (true);
unpaused.TransitionTo(.01f);
Time.timeScale = 1;
}
}
public void Quit()
{
Time.timeScale = 1;
#if UNITY_EDITOR
EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
public void RTArcade ()
{
Time.timeScale = 1;
SceneManager.LoadScene("HugoArcade");
canvas.enabled = false;
m_MouseLook.SetCursorLock(true);
unpaused.TransitionTo(.01f);
}
public void ResumeGame ()
{
canvas.enabled = false;
m_MouseLook.SetCursorLock (true);
unpaused.TransitionTo (.01f);
Time.timeScale = 1;
}
}
}
Add-on :
I dont get it... I tried making a backup of my scene (the one where the menu doesnt work properly) and then I started deleting stuff... to try and find out where it was freezing...
I deleted the whole gamecontroller gameobject... didnt change anything... deleted and remade camera... deleted the player and playercontroller script altogether...
eventually i deleted EVERY SINGLE THING in the scene... made a single new camera with black background... and tried it... same bug!!! menu works (open and closes with ESC key) but i cannot interact with it in any way...
I've been on this for about 20h in the last 3 days... this is crazy...
Answer by FireHawkX · Apr 27, 2016 at 01:18 AM
After more than 36 hours of thinking about nothing else... Trying everything Including deleting every single assets from my scene (AFTER making a backup of course)... I finally found out the answer!!
All the other scenes had something that "appeared" in them somehow... (I write it this way because in all 14 unity tutorials I never once added that myself)...
EventSystem... it seems that the pause menu will only work if there is an event system present in the scene!!
I remember seeing 2 or 3 posts about buttons not responding in pause menu... all of which had not a single answer like this one... I still do not understand why it was bugging out the way it was... but at least now i know how to make it work!!
Hopefully it might help someone out one day searching for a similar issues :)
Thank you so much for co$$anonymous$$g back to answer yourself!
Thanks man. It worked!! Can't believe i missed out something that small but important :P
Your answer
Follow this Question
Related Questions
C# Disabling Camera moving while in Pause Menu 1 Answer
Cascading dropdown menus 0 Answers
Update() function keeps running AFTER script is disabled... 1 Answer
IEnumerator instead of LateUpdate in unity 1 Answer
Help with pause menu? 0 Answers