Question by
EnderNicky · Sep 03, 2015 at 10:44 AM ·
unity 5double-clickdouble-tap
How to detect double click on ui image?
Is there a simple way for detecting double click on images in the UI in Unity 5? Or can it be only done by counting time between clicks?
My question is for a project made for mobile devices.
Comment
Answer by Positive7 · Sep 03, 2015 at 11:23 AM
Attach it to GameObject you want to handle double click :
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
public class DoubleClick : MonoBehaviour, IPointerDownHandler
{
public void OnPointerDown (PointerEventData eventData)
{
if(eventData.clickCount == 2){
Debug.Log ("Double Click");
eventData.clickCount = 0;
}
}
}
This is the common solution, but a poor solution since if you are of course normally collecting single-clicks (using a drag from UI Button), that other function will fire twice!
Your answer
Follow this Question
Related Questions
Frustrating UnityAds Please help 0 Answers
How do GameObjects detect void Update and how to make my custom one. 0 Answers
long lag using unity remote and arduino uno 0 Answers
Assigning Asset Bundle in Script 2 Answers
how to use collider on eagle 0 Answers