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;
}
}
}