- Home /
Question by
pinkusrg · Jan 07, 2018 at 02:06 PM ·
inputscripting beginnerkeyboard
How to get a key hold to do something which is stored in a variable as KeyCode ?
Instead of KeyCode.W below -
if(Input.GetKey(KeyCode.W)) { GetComponent().velocity = Vector2.up speed 4; }
Comment
I'm not sure if this is what you mean, but you can store $$anonymous$$eyCode in variables like this:
void Update()
{
$$anonymous$$eyCode keycode = $$anonymous$$eyCode.W;
if (Input.Get$$anonymous$$ey(keycode))
{
// Do stuff
}
}
Answer by EmmetOT · Jan 07, 2018 at 04:52 PM
Just use the KeyCode variable in place of KeyCode.W?
KeyCode keyCodeVariable = KeyCode.W;
private void Update()
{
if (Input.GetKey(keyCodeVariable))
...
}
Your answer
Follow this Question
Related Questions
Add Mobile Android and iOS Emojis 1 Answer
No keyboard events detected after any key is held. 0 Answers
Need help with disabiling keyboard inputs. 1 Answer
LeftControl key at runtime 0 Answers
Add keyboard input in ClickToMove 0 Answers