The question is answered, right answer was accepted
How to prevent a variable used in two functions from being overridden? [SOLVED]
So I'm trying to develop a fighting game and I 've come at a bit of an issue. I'm trying to assign different values to a variable depending on the button being pressed. if (Input.GetKey(KeyCode.D)) { MovingState = 1; } else { MovingState = 0; } if (Input.GetKey(KeyCode.A)) { MovingState = 2; } else { MovingState = 0; }
When I press D I want "MovingState" to equal 1, and when I press A, I want it to equal 2. The problem is that for whatever reason, I can never get "MovingState" to equal 1 when both inputs are being read. When I remove the A input function however, I can get it to equal 1, no problem. I believe that the A input is overriding the D input, but I'm not sure how.
Answer by Hasster1 · Dec 31, 2020 at 11:01 AM
Maybe you can try to do something like that: if (Input.GetKey(KeyCode.D)) { MovingState = 1; } else if (Input.GetKey(KeyCode.A)) { MovingState = 2; } else { MovingState = 0; }
Follow this Question
Related Questions
Vive input help 0 Answers
Input System preview - Gamepad not detected 0 Answers
my wireless switch Gamecube controller is read as a "Lic Pro Controller" how do I fix it 0 Answers
Unity setting up custom HID item 0 Answers
How to create and set different Player ID's to individual controllers? 1 Answer