MouseDown on GUI.button

Hi,

I want to check if I am holding down my mouse when using a GUI.button. I have been searching the forum but I can't find anything that works:

here is how a single mouse click works. Only thing left to do is check for mouseDown instead of mouseClick

if (GUI.Button(new Rect(Screen.width / 2 - 50 , Screen.height - 40, 25, 25), "", "leftArrow"))
    {
        //do something
    }

Have you tried RepeatButton

:- Make a button that is active as long as the user holds it down.

What you're looking for is the UI widget 'RepeatButton' which repeatedly returns true while the user holds left mouse button down over it:

http://unity3d.com/support/documentation/ScriptReference/GUI.RepeatButton.html http://unity3d.com/support/documentation/ScriptReference/GUILayout.RepeatButton.html

Have a look at this.

http://unity3d.com/support/documentation/ScriptReference/Input.GetButton.html

RepeatButton not always good. For example:

You need to make button for defender game…

bool buttonPresed = false;//to hide button after first mouseDown
Rect rectMG  = new Rect(x,y,w,h)//Machine gun rect
Texture t1;// button texture

if(!buttonPresed){
   if(GUI.RepeatButton(rectMG, t1, buttonStyle)){
	if(CheckResources(machineGunCost)){
	  InstantiateTGhost(machineGunGhost, machineGunCost);
	}
   }
}

… this wil be work, but: If you will make “mouseOver” it will still work.
It happens only on standalone platform (Mac/PC). On mobile everything is OK,
because no “moseOver” exists on it.