Keycode returning none even when I filter KeyCode.None out?
Hi all, I'm trying to set up a key bindings menu in my game. To do this, I'm checking if both any key is being held and a UI Button is clicked. Since GetKey returns KeyCode.None if no key is being pressed, I've tried to filter KeyCode.None by checking for it at pretty much every step of the process. But somehow, my "a" variable is still being set to None. Can anyone see why that would be happening? Sorry if the answer is obvious.
void OnGUI()
{
e = Event.current;
if (e.isKey && (e.keyCode != KeyCode.None))
{
Debug.Log(e.keyCode); //this debug statement returns the actual key I am holding.
if (e.type == EventType.KeyDown && (e.keyCode != KeyCode.None))
{
a = e;
keyHeld = true;
}
if (e.type == EventType.KeyUp)
{
keyHeld = false;
}
}
}
void Clicked()
{
if(keyHeld == true)
{
myKC = a.keyCode;
Debug.Log("e is" + e.keyCode); // all these debug statements are saying they are None even though they should be working above
Debug.Log("a is" + a.keyCode);
Debug.Log("its" + myKC);
}
}
Your answer
Follow this Question
Related Questions
I have created an Event based InputManager 0 Answers
Way to assign event fields in created at runtime scriptable object (ScriptableObject Architecture) 0 Answers
Unity Events not registering a function due to custom parameters 0 Answers
Error with calling events from other scripts 3 Answers
[Solved] Scroll not working when elements inside have click events 3 Answers