- Home /
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); }
}
do you want to detect a double click? or detect any number of multiple clicks?
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
Perhaps you can't detect double click events while your caps lock is on!
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");
}
}
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");
}
}
}
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;
}
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;
}
Answer by Marolop · Jun 04, 2012 at 07:25 AM
void OnGUI ()
{
Event Mouse= Event.current;
if (Mouse.clickCount == 2)
{
print("Double Click");
}
}
Your answer
Follow this Question
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