I am working on a game that has similar player mechanics as Subway Surfers, i.e. the player switches lanes when the user gives its corresponding input.
private void Update() {
if (Input.GetKeyDown(KeyCode.A)) {
ChangeLane(-1);
} else if (Input.GetKeyDown(KeyCode.D)) {
ChangeLane(1);
}
}
This snippet basically checks for user input and makes the user switch lanes using ChangeLane(int) method, argument -1 implies the player's switching to the left lane, and 1 implies the player's switching to the right lane.
Question:
I want to check for both WASD keys and arrow keys input simultaneously in my script.
What comes to mind immediately after thinking about this:
if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) { ... }
I would like to do something that checks for both A and the left arrow with only one if check and not both separately as shown above.
What I have tried:
Input.GetAxis("Horizontal"), but this doesn't work in this case as this value gets incremented until 1 as long as the key is pressed.
Next, Input.GetAxisRaw("Horizontal"), this almost worked, returns 1 as soon as the key is pressed.
int horizontalInput = (int)Input.GetAxisRaw("Horizontal");
if (horizontalInput != 0) {
ChangeLane(horizontalInput);
}
My Horizontal Axis in Input Manager:

But....
Input.GetAxis(string) and Input.GetAxisRaw(string) works similar to Input.GetKey(KeyCode) but I want something that works as Input.GetKeyDown(KeyCode).
PS: I would appreciate an answer that doesn't include getting away with boolean flags to skip frames after the button is pressed down.
