- Home /
lcokCursor for ingame menu doesn't work, NEED HELP!!!
I am trying to create a simple in game menu but I just can't get it to work. Everything looks fine, it doesn't work and it keeps doing wired stuff (like if I am standing in front of an interactive charactor in my game, the code works!) Otherwise the cursor will not lock. It seems like the cursor is constantly being locked and unlocked somehow. Please help.
var menuSkin : GUISkin;
private var openMenu : boolean = false;
function OnGUI()
{
if(openMenu)
{
Time.timeScale = 0;
GUI.skin = menuSkin;
GUI.Box(Rect((Screen.width/2)-100,(Screen.height/2)-110,200,220),"");
if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)-100, 200, 60),"Resume"))
{
Screen.lockCursor = true;
openMenu = false;
}
if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)-30, 200, 60),"Main Menu"))
{
openMenu = false;
OpenLevel("Deadly Nightshade Start Menu");
}
if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)+40, 200, 60),"Quit"))
{
Application.Quit();
}
}
else
Time.timeScale = 1;
}
function Update()
{
if(!openMenu && Input.GetButtonDown("Q"))
{
openMenu = true;
Screen.lockCursor = false;
}
else if(openMenu && Input.GetButtonDown("Q"))
{
openMenu = false;
Screen.lockCursor = true;
}
}
function OpenLevel(level:String)
{
//audio.PlayOneShot(beep);
Application.LoadLevel(level);
}
no idea what to tell you, I copy-pasted your code to a test script attached to a camera in an empty scene, just changed input button "Q" to "Fire2" which is defined by default and commented out the call to OpenLevel, and it seems to work fine.
Since the script itself seems fine, it must be something else. What are you attaching this script to? Does any other script access this one? What is your build target? If web, what browsers are you testing in?
Answer by liu264 · Nov 28, 2011 at 05:35 AM
I fixed it. Remember when I said if I am standing in front of an interactive character in my game, the code works. That's why, I locked the cursor when checking states in my interactive GUI code.
Your answer
![](https://koobas.hobune.stream/wayback/20220613055319im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hiding the cursor on a certain level. Pause Menu help. 2 Answers
My Mouse Cursor is locked in certain scenes 1 Answer
how to show cursor on specific time? 2 Answers
Unity 3D C# - Scripts ot true false not working 2 Answers
Returning to main menu 1 Answer