Created
October 1, 2017 16:19
-
-
Save arunkarnann/376fec718eb38801c33861e61b75bf24 to your computer and use it in GitHub Desktop.
Double Tap detection Unity3D Games..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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