- Home /
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
}
Answer by diabloroxx · Dec 21, 2010 at 08:49 PM
Have you tried RepeatButton
:- Make a button that is active as long as the user holds it down.
Answer by heks · Dec 21, 2010 at 08:53 PM
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
Answer by dissidently · Dec 21, 2010 at 08:32 PM
Have a look at this.
http://unity3d.com/support/documentation/ScriptReference/Input.GetButton.html
Answer by SeveneduS · May 29, 2014 at 04:13 AM
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.
Your answer
Follow this Question
Related Questions
Detect Mouse Click OnGUI 1 Answer
GUI Button OnMouseUp? 2 Answers
How to fire gui button on mouse right release 2 Answers
2 Bugs in my game: mouse control takes some time to load and Menu not working. 0 Answers
OnMouseDown() Doesn't work 17 Answers