How to get either keypress in one bool?

Right now I have these lines of code that detect if the “up” arrowkey is pressed;

bool arrowpress = Input.GetKey (“up”);

This is then followed by an If…statement that, if true, will play a sound.

However, I want to play a sound if either “up”, “down”, “left” or “right” is pressed. Is there any way I can do this one one bool? I.e. something along the lines of:
bool arrowpress = Input.GetKey (“up”) OR (“down”) OR (“left”) OR (“right”);

Much obliged…

if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)) {
            //Play sound;
        }

or

bool arrowPress = (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)) ? true : false;

        if (arrowPress) {
            //Play sound;
        }
3 Likes

Ok, that easy, huh? :slight_smile: Works great, thanks for the help!