I have tried to make an options screen and got stuck at how to change one key to another…
I press the GUI button and then it wont detect if i hold any key down
if(GUI.Button(Rect(95,55,75,30), GLOBAL.keyForward))
{
//start setNewKey function for the GLOBAL.keyForward
//(GLOBAL.js -> static var keyForward = "W";)
setNewKey(GLOBAL.keyForward);
setKey = true;
}
function setNewKey(KEY)
{
while(setKey)
{
if(Input.anyKey) //Think my problem is here
{
KEY = Input.inputString;
setKey = !setKey;
}
}
}
Full script:
var currMenu : int = 0;
var currOptMenu : int = 0;
/////////////////////////////////////////////////////////////////
var showOptions : boolean = true;
var optionsPos = Rect(Screen.width + 120, 20, 550, 350);
var setKey : boolean = false;
//Buttons etc. inside:
function DoOptions (windowID : int) {
if(GUI.Button(Rect(10,20,125,30), "Game")) {
currOptMenu = 0;
}
if(GUI.Button(Rect(145,20,125,30), "Video")) {
currOptMenu = 1;
}
if(GUI.Button(Rect(280,20,125,30), "Audio")) {
currOptMenu = 2;
}
if(GUI.Button(Rect(415,20,125,30), "Controlls")) {
currOptMenu = 3;
}
switch(currOptMenu)
{
//~skipped case 0-2 since i have no probs here
case 3: //Controlls
GUI.Label(Rect(20,60,75,20),"Forward");
if(GUI.Button(Rect(95,55,75,30), GLOBAL.keyForward))
{
setNewKey(GLOBAL.keyForward);
setKey = true;
}
break;
}
if(setKey)
GUI.Label(Rect(20,120,75,20),"switch");
GUI.DragWindow ();
}
function setNewKey(KEY)
{
while(setKey)
{
if(Input.anyKey)
{
print("Key was changed");
KEY = Input.inputString;
setKey = !setKey;
}
}
}
////////////////////////////////////////////////////////////////
function OnGUI()
{
// Open/close optionsBox
showOptions = GUI.Toggle (Rect (100,10,100,20), showOptions, "Window 0");
if (showOptions)
optionsPos = GUI.Window (0, optionsPos, DoOptions, "My Window");
}