- Home /
Mouse Movement In Pause Menu
Hey guys! i have a problem. When i go into my pause menu i get the mouse showing, but i gets stuck in the middle of the screen. when i playtest in Unity i can use the mouse, but as soon as i do it as a builded version, it gets stuck :(
Here is my code for the pausemenu:
using UnityEngine; using System.Collections;
public class Pause : MonoBehaviour {
private ShowPanels showPanels;
private bool isPaused;
private StartOptions startScript;
void Awake()
{
showPanels = GetComponent<ShowPanels> ();
startScript = GetComponent<StartOptions> ();
}
void Update () {
if (Input.GetButtonDown ("Cancel") && !isPaused && !startScript.inMainMenu)
{
DoPause();
}
else if (Input.GetButtonDown ("Cancel") && isPaused && !startScript.inMainMenu)
{
UnPause ();
}
}
public void DoPause()
{
isPaused = true;
Time.timeScale = 0;
showPanels.ShowPausePanel ();
GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = false;
Cursor.visible = true;
}
public void UnPause()
{
isPaused = false;
Time.timeScale = 1;
showPanels.HidePausePanel ();
GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = true;
Cursor.visible = false;
}
}
Answer by nullgobz · Aug 09, 2015 at 01:26 PM
Try these:
Cursor.lockState = CursorLockMode.Locked;
Cursor.lockState = CursorLockMode.Confined;
Cursor.lockState = CursorLockMode.None;
Basicly do:
Cursor.lockState = CursorLockMode.Confined;
On pause, and:
Cursor.lockState = CursorLockMode.Locked;
On unpause.
Note that lockState has been buggy in Unity 5. It might or might not work.
Your answer
Follow this Question
Related Questions
Please help my head is burning from this problem : i have multiple gameobject , same script 1 Answer
Moving First person controller Vertically using Mouse ? 0 Answers
Unity Ui. Why constant pixel size option in Canvas Scaler don't work with mouse? 1 Answer
Want to move object slowly to where the mouse clicks? 1 Answer
UnityEngine.UI.dll 0 Answers