x


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

Jorn gravatar image

Jorn
52 8 6 10

(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

diabloroxx gravatar image

diabloroxx
737 13 12 21

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

heks gravatar image

heks
76 3

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

dissidently gravatar image

dissidently
475 132 105 113

(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 at 04:13 AM

SeveneduS gravatar image

SeveneduS
16 2

(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:

x5491
x1395
x1242
x73

asked: Dec 21, 2010 at 08:14 PM

Seen: 11093 times

Last Updated: May 29 at 04:14 AM