Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 robert 4 · Feb 21, 2011 at 09:33 PM · eventdouble-click

Double click events

How to display double click events in GUI.Label when user click on the screen how to display how single or double click on gui.label

function OnGUI() { var e : Event = Event.current; if (e.isMouse) { GUI.Label (Rect (10, 10, 150, 20),"Mouse clicks: " +e.clickCount ); print("Mouse clicks: " + e.clickCount); }

}

Comment
Add comment · Show 4
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 poncho · Feb 21, 2011 at 09:52 PM 0
Share

do you want to detect a double click? or detect any number of multiple clicks?

avatar image robert 4 · Feb 21, 2011 at 10:12 PM 0
Share

I WANT TO DETECT A DOUBLE CLIC$$anonymous$$ IN THIS CASE IN ANOTHER CASE I WANT TO DETECT ANY NU$$anonymous$$BER OF $$anonymous$$ULTIPLE CLIC$$anonymous$$ ON A BUUTON CAN U PLEASE EXPLAIN BOTH

avatar image · Feb 22, 2011 at 12:07 AM 5
Share

Perhaps you can't detect double click events while your caps lock is on!

avatar image Bunny83 · Feb 22, 2011 at 02:21 AM 0
Share
@robert: Well, you should check for e.capsLock as well ;)

5 Replies

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

Answer by Bunny83 · Feb 22, 2011 at 02:19 AM

Well, to detect a double click do that:

 // UnityScript
 function OnGUI() 
 {
     var e : Event = Event.current;
     if (e.isMouse && e.type == EventType.MouseDown && e.clickCount == 2)
     {
         // Double click event
         Debug.Log("Double click");
     }
 }
             
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
2

Answer by Guan · Mar 03, 2016 at 03:19 PM

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 public class TestEditorWindow : EditorWindow {
     [MenuItem("nima/hehhe")]
     static void HEHE()
     {
         GetWindow <TestEditorWindow>().Show ();
     }
     double lastdoubleClicktime;
     void OnGUI()
     {
         if (Event.current != null && Event.current.clickCount == 2) {
             lastdoubleClicktime = EditorApplication.timeSinceStartup;
         }
         if (GUILayout.Button("TEST")) {
             if (EditorApplication.timeSinceStartup - lastdoubleClicktime < .8f) {
                 Debug.Log ("I think this is a double click");
             } 
     }
 
 }

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
1

Answer by superboy007 · Oct 25, 2013 at 11:34 AM

bool mouseClicksStarted = false; int mouseClicks = 0; float mouseTimerLimit = .25f;

 public void OnClick(){
     mouseClicks++;
     if(mouseClicksStarted){
         return;
     }
     mouseClicksStarted = true;
     Invoke("checkMouseDoubleClick",mouseTimerLimit);
 }
 
  
 private void checkMouseDoubleClick()
 {
     if(mouseClicks > 1){
         Debug.Log("Double Clickedd");
         
     }else{
         Debug.Log("Single Clicked");
         
     }
     mouseClicksStarted = false;
     mouseClicks = 0;
 }
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
1
Wiki

Answer by Urza · Mar 20, 2014 at 02:16 PM

i made this for double-click actions. Contributing -->

   if(DoubleClick()){
     //do something..
   }


 float clicked = 0;
 float clicktime = 0;
 float clickdelay = 0.5f;
 
 bool DoubleClick(){
         if (Input.GetMouseButtonDown (0)) {
             clicked++;
             if (clicked == 1) clicktime = Time.time;
         }         
         if (clicked > 1 && Time.time - clicktime < clickdelay) {
             clicked = 0;
             clicktime = 0;
             return true;
         } else if (clicked > 2 || Time.time - clicktime > 1) clicked = 0;         
         return false;
     }



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 Marolop · Jun 04, 2012 at 07:25 AM

void OnGUI ()

{

    Event Mouse= Event.current;
          if (Mouse.clickCount == 2)
          {
            
             print("Double Click");
            
          }
  }
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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to listen for Double clicks on selection grid elements ? 1 Answer

GetMouseButtonDown strange behaviour 0 Answers

How do I add an event listener for the WWW class? 1 Answer

NSEvents and Unity 0 Answers

Boo Events 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges