- Home /
GetKeyDown Bug
My bug is that the GetKeyDown doesn't work as intended, it seems random when its working or not and I have no idea what could be causing the problem. Code:
function Update() {
if (Network.isServer || Network.isClient) {
ShowInGameGUI = true;
} else {
ShowInGameGUI = false
}
if (ShowInventory) {
if (Input.GetKeyDown(KeyCode.Escape)) {
ShowInventory = false;
return;
}
}
if (!ShowInventory) {
if (Holding) {
var Holding = false;
var CurrentHolding = new item();
var CurrentHNumber = -1;
}
}
if (ShowInGameGUI) {
if ( player == null) {
player = GameObject.Find(PlayerPrefs.GetString("Username"));
}
//Show in-game GUI
if (Input.GetButtonDown("Inventory")) {
if (ShowPauseMenu) {
return;
}
ShowInventory = !ShowInventory;
}
if (Input.GetButtonDown("Cancel")) {
if (ShowInventory) {
ShowInventory = false;
return;
}
ShowPauseMenu = !ShowPauseMenu;
}
if (ShowPauseMenu || ShowInventory) {
mouse(false);
//It seems like these lines are making the game unfocus, so each time you toggle the inventory you will need to click on the game again.
Screen.lockCursor = false;
Screen.showCursor = true;
} else {
mouse(true);
Screen.lockCursor = true;
Screen.showCursor = false;
}
}
}
Would the GUI Code help finding the issue?, maybe some overload when calling or something...
Post more info, please. Like "expected" and "actual" results.
The problem is that the when toggling the inventory it will show, but also block all Get$$anonymous$$eyDown calls for about 1 $$anonymous$$ute.
If Alpha is a key youve specified in Input manager, you use ("Alpha") ins$$anonymous$$d of $$anonymous$$eyCode, I do believe.
ahh.. i'm going to hell.
@meat5000, the Alpha keys are defined by unity as the numeric keys on the number pad
Answer by blackshtormx · Aug 31, 2014 at 03:27 PM
if (Input.GetKeyDown("Cancel")) {
if (ShowInventory) {
ShowInventory = false;
return;
}
you have to write "getkeydown" try it :) it should work.
Your answer
Follow this Question
Related Questions
Neutral state for toggle buttons? 2 Answers
GUI window popup button 1 Answer
Little help with GUI Toggle needed 1 Answer
EditorGUI elements require minimum size of 24px? 0 Answers
GuiTexture toggle on keypress. 2 Answers