Double Tap Not Working As Expected

Hey all,

Trying to fix this double click issue but no luck.
And its not working.

private float lastClickTime;

public float catchTime = 0.25f;

if (touch.position.x < Screen.width/2 && Time.time - lastClickTime < catchTime)
             {
                 if(panger.randomDirection == 0)
                         {
                                 rb.AddForce(new Vector3(-4, 5, 4), ForceMode.Impulse);
                                 rb.velocity = Vector3.zero;
                         }
}

else  if (touch.position.x > Screen.width/2 && Time.time - lastClickTime > catchTime)
             {
                 if(panager.randomDirection == 0)
                         {
                                 rb.AddForce(new Vector3(4f, 5f, 8f), ForceMode.Impulse);
                                 rb.velocity = Vector3.zero;
                         }
}

dont you need to reset the lastClickTime to Time.time; afterwards?
lastClickTime = Time.time;

Hey thanks for answer.
I actually did it but forgot to paste it here.
It was after the else if function.

But still not working.

So I Had To Check Up On My Stuff ,
i guess you’ll have to check for 0, first and then inside those your “ifs”
set it to zero
i do it like so

if (doubleClickTimer != 0) {
                        if (Time.time - doubleClickTimer < DOUBLECLICKTIMERTHRESHOLD) {
                            Debug.Log ("This Fires on double click");
                            doubleClickTimer = 0;
                        } 
                        else 
                        {
                            doubleClickTimer = Time.time;
                        }
                    } else {
                        doubleClickTimer = Time.time;
                    }

Hey,
I tried your way and everything.
But still not working.

Here is my full code:

private float lastClickTime;

public float catchTime = 0.25f;

 void Update ()
    {  
       if(Input.touchCount > 0 && isGrounded == true)
    {
        Touch touch = Input.GetTouch(0);
        if(touch.position.x < Screen.width/2 && Time.time - lastClickTime < catchTime)
        {
             if(pathManager.randomDirection == 0)
                         {
                                 rb.AddForce(new Vector3(-4, 5, 4), ForceMode.Impulse);
                                 rb.velocity = Vector3.zero;
                         }
                 else if(pathManager.randomDirection == 1)
                         {
                                rb.AddForce(new Vector3(-4, 5, 4), ForceMode.Impulse);
                                rb.velocity = Vector3.zero;
                         }
                else if(pathManager.randomDirection == 2)
                         {
                                rb.AddForce(new Vector3(-4, 5, 4), ForceMode.Impulse);
                                rb.velocity = Vector3.zero;
                         }
                else if(pathManager.randomDirection == 3)
                         {
                                rb.AddForce(new Vector3(-4, 5, 4), ForceMode.Impulse);
                                rb.velocity = Vector3.zero;
                         }

        }
else  if (touch.position.x > Screen.width/2 && Time.time - lastClickTime < catchTime)
             {
                 if(pathManager.randomDirection == 0)
                         {
                                 rb.AddForce(new Vector3(4, 5, 4), ForceMode.Impulse);
                                 rb.velocity = Vector3.zero;
                         }
                 else if(pathManager.randomDirection == 1)
                         {
                                rb.AddForce(new Vector3(4, 5, 4), ForceMode.Impulse);
                                rb.velocity = Vector3.zero;
                         }
                else if(pathManager.randomDirection == 2)
                         {
                                rb.AddForce(new Vector3(4, 5, 4), ForceMode.Impulse);
                                rb.velocity = Vector3.zero;
                         }
                else if(pathManager.randomDirection == 3)
                         {
                                rb.AddForce(new Vector3(4, 5, 4), ForceMode.Impulse);
                                rb.velocity = Vector3.zero;
                         }
             }
lastClickTime = Time.time;
    }

It doesn’t event detect double tap.

unfortunately i don’t do androids or input.touch in general
you could try to delete temporarily the “&& isGrounded == true” in the very first if statement so you know it doesnt have to do anything with that.
maybe some of these links could help
https://answers.unity.com/questions/369230/how-to-detect-double-tap-in-android.html ← Bouzy answer
http://unity3dworkouts.blogspot.com/2015/09/double-tap-single-tap-swipe-all.html
https://sushanta1991.blogspot.com/2013/10/how-to-detect-double-tap-on-touch.html or this, though you’d have to transfer it to c# : - )

1 Like