One tap or double tap

How can i distinguish between one tap and a double tap? If i use the iPhoneTouch.tapCount Variable it counts the first tap and then the second tap. So if i have somthing like that(pseudocode) :

if(tapCount ==1) 
       dothis();
else if(tapCount ==2)
       dothat():

if i make a doubletap first he goes to the dothis() method and then to dothat() method.

1 Like

You could check the touch’s time. Something like:

if (tapcount == 1  tap.time > 0.5)
     dothis ();
else if (tapcount ==2)
     dothat();

Try this for a single tap:

if (iPhoneInput.touchCount == 1) { 
       if (iPhoneInput.GetTouch(0).tapCount == 1) { 
    	Debug.Log ("SingleTap"); 
      }  
}

This is a Double Tap

if (iPhoneInput.touchCount == 1) {      
     if(iPhoneInput.GetTouch(0).tapCount == 2) {
      	Debug.Log("DoubleTap");
      }
}

Tap Count is how many taps, and Touch Count is how many fingers.

yes thats clear… and thats exactly the problem… do you tested this code? if i make a double tap first “single tap” is printed and then “double tap” is printed.

You’ll have to add in some timer code with that example, so if you combine the suggestions above this should work. The problem is that there is no clear definition of a double tap. You need to figure out how long you want to wait before it is two single taps.

how about using else ?

function TapCount()
{
	if (iPhoneInput.touchCount == 1)
	{
	       if (iPhoneInput.GetTouch(0).tapCount == 1)
			{
	       		Debug.Log ("SingleTap "+Time.time);
	      	} else if(iPhoneInput.GetTouch(0).tapCount == 2)
			{
		         Debug.Log("DoubleTap "+Time.time);
	      	}
	}	
} 	

function Update () {
	TapCount();
}

great suggestion :roll: … do you test your code? first it will print Single tap and then double tap

… but yheah jeffcraighead i have to find a way with a timer

Sorry, Ive been busy at work. If your going to put these statements into the same script then I think you need to change this line here for a DoubleTap :

if (iPhoneInput.touchCount == 1) {      
     if(iPhoneInput.GetTouch(1).tapCount == 2) { 
         Debug.Log("DoubleTap"); 
      } 
}

Changing the GetTouch() to 1 instead of 0 should help.

nope, only if you touch very fast