Skip to content

Instantly share code, notes, and snippets.

@arunkarnann
Created October 1, 2017 16:19
Show Gist options
  • Save arunkarnann/376fec718eb38801c33861e61b75bf24 to your computer and use it in GitHub Desktop.
Save arunkarnann/376fec718eb38801c33861e61b75bf24 to your computer and use it in GitHub Desktop.
Double Tap detection Unity3D Games..
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchDetection : MonoBehaviour {
bool singleTouch;
float doubleClickSpeed = 1.5f;
float timeElapsed = 0.0f;
void Update(){
if (!singleTouch) {
if (Input.GetMouseButtonDown (0)) {
print (" Single Tap");
singleTouch = true;
//timeElapsed += Time.deltaTime;
}
} else {
if (Input.GetMouseButtonDown (0)) {
print ("Double Tap");
print ("Time since last Touch" + timeElapsed);
singleTouch = false;
timeElapsed = 0f;
}
}
if(singleTouch){
timeElapsed += Time.deltaTime;
}
if (timeElapsed > doubleClickSpeed) {
print ("Values Resetted");
timeElapsed = 0f;
singleTouch = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment