- Home /
Pause Menu issue with mouse
Hey guys, just wondering how i can get my mouse to stay active while in the pause menu, it pops up fine, but then when any buttons are click the Cursor disappears, Have tried with and without 'Cursor.visable = true" and same outcome, have tried looking in Scripting API for Cursor.lockState, but cannot find any coding in relation to C#
Here is the coding for my pausemenu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.Characters.FirstPerson;
public class PauseMenu : MonoBehaviour {
public GameObject Player;
GameObject PauseCanvas;
bool paused;
// Use this for initialization
void Start () {
PauseCanvas = GameObject.Find("PauseMenu");
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Escape))
{
paused = !paused;
}
if (paused)
{
//GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = false;
PauseCanvas.SetActive(true);
Time.timeScale = 0;
//Cursor.visible = true;
} else if (!paused)
{
//GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = true;
PauseCanvas.SetActive(false);
Time.timeScale = 1;
//Cursor.visible = false;
}
}
public void Resume()
{
paused = false;
}
public void Quit()
{
SceneManager.LoadScene("MainMenu");
}
}
Also upon loading the 'MainMenu' from the Quit() void, my main camera animation on that scene fails to start, it loads but just sits at the very start without animating.
Have provided a Video to assist in providing the right help. Youtube Video Link
@crazyKnight @MikeNewall @alejandro-unity
'@' Tagged due to all posts being moderated upon post
What kind of buttons lead to disappearing mouse (UI buttons)? Do they have their own scripts? During the gameplay the cursor is disabled? If yes, do you disable it in another script?
Just my settings button as is is the only button that attempts to open up a second canvas and doesn't do action on that single click, it use to do it with my Exit Game Button also, but to overcome that issue was to remove the confirmation canvas "are you sure you want to exit" and just exit the game on that button click, but even if i don't click on a button just in a blank space on the pause menu the mouse still disappears, the settings canvas wont even open when i click on settings anyway, so its not even getting to the point of activating the settings canvas script.
EDIT: Also if you have a look at the video i have provided it may make everything clearer
Answer by ScaniX · Jan 07, 2017 at 12:08 AM
Are you using the RigidbodyFirstPersonController or probably just the MouseLook script component somewhere else?
The MouseLook locks and hides the mouse cursor on release of the left mouse button. To avoid this, call SetCursorLock(false) on the MouseLook.
PS: As for the animation problem: You need to ensure that the Time.timeScale is set back to 1 when leaving the menu, no matter in what way. If you want to keep the timeScale at zero, you can still play animations by setting them to use unscaledTime.
i am using a RigidbodyFirstPersonController from the standard assets. and thank you for the the animation tip, so should i set the timescale back to 1 within the Quit void? or on a start function in the $$anonymous$$ain$$anonymous$$enu Scene?
I am making sure that the code that sets it to something different than 1 will set it back to normal in the end. That is the case for every effect or mode that I set to something different than "normal".
As an additional safety hook I have a global reset call at certain points (e.g. start of level) that will reset all those states like timeScale, player interaction mode, visual fx, etc. in case something unpredictable has happened. After years in this job I can say that the only thing that is 100% certain is the unpredictable. ;)
Thank you so much for this answere. I literally searched 3 hours to fix my "after escape-menu cursor show up" - Bug and it was the $$anonymous$$ouseLook. :-)