- Home /
How do I enable mouse cursor on my main menu?
I want to enable the cursor on my main menu, but I have a problem. Normally I would press escape to make the mouse appear, but when I do that my pause menu appears. I'm not sure how to fix this.
Here is my pause menu script: #pragma strict
//This script is a simple pause menu. //This script was made by www.Twitch.tv/Funnyguy77 CHECK ME OUT!!
//scripToControl handles toggling the ability to move the camera on and off. private var scriptToControl : UnityStandardAssets.Characters.FirstPerson.FirstPersonController; var cursorLockMode; var Sound : AudioClip; var pauseMenu : GameObject; var pauseSettings : GameObject; private var pauseOn : boolean; private var settingsOn : boolean; private var cursorLocked : boolean;
function Start() { scriptToControl = GetComponent("FirstPersonController"); pauseOn = false; settingsOn = false; //Locks cursor. Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; cursorLocked = true; }
function Update() { if(cursorLocked == true) { //Locks cursor again. Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; }
if(cursorLocked == false)
{
//Locks cursor again.
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
//Handles when the player presses escape.
if(Input.GetKeyDown("escape"))
{
pauseOn = true;
scriptToControl.enabled = false;
GetComponent.<AudioSource>().PlayOneShot(Sound);
cursorLocked = false;
}
//Handles main pause menu toggle.
if(pauseOn == true)
{
pauseMenu.GetComponent(CanvasGroup).alpha = 1f;
pauseSettings.GetComponent(CanvasGroup).alpha = 0f;
pauseSettings.SetActive(false);
}
if(pauseOn == false)
{
pauseMenu.GetComponent(CanvasGroup).alpha = 0f;
pauseSettings.GetComponent(CanvasGroup).alpha = 0f;
pauseSettings.SetActive(false);
}
//Handles settings menu toggle.
if(settingsOn == true)
{
pauseMenu.GetComponent(CanvasGroup).alpha = 0f;
pauseMenu.SetActive(false);
pauseSettings.GetComponent(CanvasGroup).alpha = 1f;
pauseSettings.SetActive(true);
}
}
//Apply this function to your settings button function SettingsButton() { settingsOn = true; }
//Apply this function to your resume button. function ResumeButton() { scriptToControl.enabled = true; pauseOn = false; settingsOn = false; cursorLocked = true; }
//This function will be applied to the back button on the settings menu. function Back() { pauseSettings.GetComponent(CanvasGroup).alpha = 0f; pauseSettings.SetActive(false); pauseMenu.GetComponent(CanvasGroup).alpha = 1f; }
Your answer
Follow this Question
Related Questions
Show cursor on screen 0 Answers
After disabling then enabling this script it stops working anyone know why? 1 Answer
GUI cursor position off 1 Answer
how to stop mouse going out of the screen ? 9 Answers
How do I change the hardware cursor? 5 Answers