If statement question

Hey,

Is it possible to simplify :

if ((Input.GetButtonDown("Attack") || Input.GetButtonDown("Escape") || Input.GetButtonDown("Start")) || Input.GetButtonDown("Select"))

Isn’t there a way to just have the Input.GetButtonDown once, something like :

if (Input.GetButtonDown("Attack" || "Escape" || "Start" || "Select"))

Thanks.

This is possible with a few variables. It doesn’t get rid of the Input calls, but it does simplify the branch condition.

bool Attack = Input.GetButtonDown ("Attack");
bool Escape= Input.GetButtonDown ("Escape");
bool Start= Input.GetButtonDown ("Start");
bool Select= Input.GetButtonDown ("Select");

 if (Attack || Escape || Start || Select) {
    // ...
}

No. There are some specific things (like layers) where you can bitwise AND and OR things together like that but not for something like this.

Try this:

using System.Linq
 public static bool GetAllButtonsDown(params string[] buttons)
{
    return buttons.All( b => Input.GetButtonDown (b));
}
public static bool GetOneButtonsDown (params string[] buttons)
{
    var check = (b) => Input.GetButtonDown (b);
    foreach (var but in buttons)
    if (check (but)){
        return true;
    }
    return false;
}