I am trying to set up a control customization dialogue, but I don’t know how to capture the user’s keypress.
Here is what I have for this so far:
if(_displayKeyChoice1 == true) {
GUI.Label(new Rect(200, // x
150, // y
100, // width
buttonHeight), // height
"Press any Key");
if(Input.anyKeyDown) {
// Insert what here?
_displayKeyChoice1 = false;
}
}
How do I grab the user’s keypress so I can assign it to the controls in my InputManager?
Also, can you tell me how to make GUI windows opaque rather than transparent?
I need to take the actual key that was pressed and assign it to the custom control in a script that I have set up.
I do not know how to read which key was pressed.
The solution I used when coding our input manager was to first setup a GUI-interface with the inputs you want to control.
GUILayout.Label("Forward");
if(GUILayout.Button("W"))
{ /* Save which input you want to change */ }
Then further down the OnGUI I had a bool controlling the reading of input.
if(changeKey)
{
Event events = Event.current;
if(events.isKey)
{ /* Store key in array of dictionary */ }
}
Then I stored all the keys in a dictionary with the dictionary key being an enum list of all the keys I used in the game.
So whenever you wanted to know the key later on in game you just typed
dictionaryOfKeys[NameOfEnum.Forward] - Which returned the keycode forward is using.