Button Click from script

Is there a way to click a button from code? :smile:

I haven’t understood ?

are you talking about GUI.Button or about keyboard keys?

OnGUI(){
if(GUI.Button(new Rect(x,y,100,100)),"button"){
someCode();
}
}

public void someCode(){
... // code 4 button click here
}

then you can use ā€œsomeCode()ā€ to call the function

Sorry for the loose question. I think i figured it out. :smile:

if your code is in function ā€˜someCode’, just call someCode() whenever you need it.