x


Before updating to Windows 10 you may need to return your Pro license. More information here

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
    }

more ▼

asked Dec 21, 2010 at 08:14 PM

avatar image

Jorn
62 9 7 13

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Have you tried RepeatButton

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

more ▼

answered Dec 21, 2010 at 08:49 PM

avatar image

diabloroxx
742 14 17 40

thanks for the help!

Dec 22, 2010 at 10:26 AM Jorn
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Dec 21, 2010 at 08:53 PM

avatar image

heks
86 1 1 4

Thanks for your help!

Dec 22, 2010 at 10:26 AM Jorn
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Dec 21, 2010 at 08:32 PM

avatar image

dissidently
560 133 108 119

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered May 29, 2014 at 04:13 AM

avatar image

SeveneduS
26 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x6714
x1923
x1648
x80

asked: Dec 21, 2010 at 08:14 PM

Seen: 14737 times

Last Updated: May 29, 2014 at 04:14 AM