Do action on key press or GUI button press?

I’m working on a project that needs to work with both the keyboard and mouse individually, I’ve made a GUI that has certain buttons, what I need is that when I press that button it has to do the same thing as when a certain key is pressed.

Like for instance, if I have a cube there’s a UI button that when pressed it explodes, the same thing needs to happen when I press the space bar.

As is I’ve been trying to do an if with an or, but haven’t been able to get a method that returns me weather or not a button has been pressed, as is the code is pretty extensive so I can’t do major changes.

Something like this

public Button boton;

if (Input.GetKeyDown(KeyCode.S)||boton is pressed)
             //Do something

You can do it this way:
You have method “void Explode()”, so make it public(or make other public method which will move to Explode():wink: and assign in to “OnClick” on button.