I had a hard time trying to solve this same problem today! You must use a RepeatButton instead - but this bastard actually returns true and false alternately each OnGUI when pressed! The solution is to use a boolean flag that’s set when RepeatButton returns true, and reset when the mouse button is released:
private var buttonDown = false;
function OnGUI(){
if (GUI.RepeatButton(new Rect(...), "shoot")){
buttonDown = true; // RepeatButton only sets buttonDown
}
// and buttonDown is reset only when the mouse button is released
buttonDown &= Input.GetMouseButton(0);
// use buttonDown to know the current button state
}
GUI.Button will return true if the mouse was pressed and released hover the rect. The mouse can be moved in between, as long as the mouse’s button isn’t released.
So actually, GUI.Button already detect if it was released.