- Home /
Question by
babji3 · Jul 16, 2015 at 08:23 AM ·
touchscriptingbasicstapdouble-tap
When i double Tap single Tap function also Executing..
Hi all, I have jump function for Single touch, and Double touch(tap) for other function, here the problem is when i double touch(tap) the single touch function also executing , here is my code.
void Update ()
{
for(int i = 0; i < Input.touchCount; i++)
{
if(Input.GetTouch(i).phase == TouchPhase.Began)
{
if(Input.GetTouch(i).tapCount == 2)
{
print("Double Touch");
StartCoroutine(SlowMotion());
}
else if(Input.GetTouch(i).tapCount == 1)
{
print("Single Touch");
if(isGameStart==true)
{
Jump();
_animator.enabled=true;
if (!this._animator.GetCurrentAnimatorStateInfo (0).IsName ("jumping1"))
{
_animator.SetBool("jumping",false);
}
else
{
_animator.SetBool("jumping",true);
}
}
}
}
}
}
Comment
Answer by fasih-uddin · Aug 01, 2016 at 02:21 PM
Its too late but might be it helps you..
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class DoubleTapScript : MonoBehaviour { // set this time as suits you float _f_afs = 0.5f; bool _b_startTimer = false;
void FixedUpdate ()
{
if (_b_startTimer == true) {
_f_afs -= Time.deltaTime;
if (_f_afs < 0) {
_b_startTimer = false;
Debug.Log ("single Tap");
// SingleTapFunctionality();
}
}
if (Input.GetMouseButtonDown (0)) {
_b_startTimer = true;
for (int i = 0; i < Input.touchCount; i++) {
if (Input.GetTouch (i).phase == TouchPhase.Began) {
if (Input.GetTouch (i).tapCount == 2) {
print ("Double Touch");
// DoubleTapFunctionality();
_b_startTimer = false;
_f_afs = 0.5f;
} else if (Input.GetTouch (i).tapCount == 1) {
// do nothing here
}
}
}
}
}
}