• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jorn · Dec 21, 2010 at 08:14 PM · guibuttonmousedown

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
    }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jorn · Dec 22, 2010 at 10:26 AM 0
Share

thanks for the help!

avatar image
3
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jorn · Dec 22, 2010 at 10:26 AM 0
Share

Thanks for your help!

avatar image
0

Answer by dissidently · Dec 21, 2010 at 08:32 PM

Have a look at this.

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Detect Mouse Click OnGUI 1 Answer

Unity UI Button touching from far distance 0 Answers

If mouse is hovering over any GUI element 0 Answers

In the new UI system is there any way to track where the mouse is when over a button or other UI control? 2 Answers

Help with resize script 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges