GUI.Button or Input.GetKey

I have a punch button that works lovely. But I would also like the ability to press the 1 key also. In C# how can I do something like this cleanly?

if(GUI.Button(new Rect(10, 10, 100, 50), “Punch”) || Input.GetButtonDown(KeyCode.Alpha1)){
print(“You Punched.”)
}

You should really be using the Event class for event handling in OnGUI(), due to the fact that the OnGUI() function has multiple passes per frame and will thus repeat Input calls more times than necessary. Instead of

if (Input.GetButtonDown(KeyCode.Alpha1)) {

try using

if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Alpha1) {

Other than that, your code is fine. What is your question?

In that case, use GetKeyDown instead of GetButtonDown.

EDIT : Using the events is quite a good idea too. OnGUI() is called twice in a frame.