Input.GetButton handling

In setting up controller support it dawned on me that I do not have a good way of determining button presses over old button presses.

As an example:

// Update is called once per frame
    void Update () {
        if (Input.GetButton("A"))
            uiText.text = "A was pressed";
        else if (Input.GetButton("B"))
            uiText.text = "B was pressed";
        else if (Input.GetButton("X"))
            uiText.text = "X was pressed";
        else if (Input.GetButton("Y"))
            uiText.text = "Y was pressed";
        else
            uiText.text = "Press any button to START";
    }

If “A” is pressed and held, B, X, and Y will never be caught by this. While there may not be a reason to hold “A,” I would still like to know a better way (such as event driven reacting to each button press/release).

Should I just remove the “else?” Of course this would lead to the issue that if “Y” is pressed and held, the text will never display “A” being pressed but, obviously, I could still process the “A” press.

Any suggestions for handling that?

Use GetButtonDown to toggle a state, then toggle it back with GetButtonUp.

–Eric

Okay, thanks.