I am making a game, where the user sets the controls before the game starts, and they can then use the keys selected in game. My question: Is there an efficient way of getting a certain key pressed other than input manager? If not, than would I have to set an input option for every single key?
Hello,
sadly you can’t edit the Input Manager at runtime (I really don’t understand why), so if you want customisable I suggest building your own Input Manager using the already existing Input
class.
For saving the different types of Input, just do something like:
static class MyInputManager {
var fire:KeyCode;
var aim:KayCode;
}
if you then want to check for an input, simply do:
if (Input.GetKey/*down/up*/(MyInputManager.fire))
If you want to change a input key, do:
MyInputManager.fire = KeyCode.Space;
If you want to check for any key, you can look through all possible keys like so:
function GetAny():KeyCode {
for (var key:KeyCode in KeyCode.GetValues(KeyCode)) {
if (Input.GetKey/*Down/up*/(key)) {
return key;
}
}
return KeyCode.None;
}
At least thats the way I like doing it
Hope this helps,
Benproductions1