So far I've tried to run a for loop while detecting a touch, and call it a tap if under X loops and a touch for over. However, that did not work nearly as well as expected. Is there a built in way to detect a tap versus a sliding touch?
In my app I assume it's a tap unless the phase becomes Moved. So when the phase is Ended, if it never became Moved, then it was a tap. This works well for (say) a scrolling list that they can either drag, or tap on one of the lines.
You could add a time limit to the above logic by adding up all the deltaTime values after the Began phase. Once the time limit is exceeded you'd treat it the same as if they moved their finger.
Remember to reset your timer and other variables when the phases Ended or Cancelled occur.
An alternative I haven't tried is using iPhoneTouch.tapCount. By reading it you might be able to detect single-taps (when the count goes to 1, get the position of the tap.) The documentation is vague on the behavior but it sounds like it has some logic for deciding when the user tapped one or more times.
answered Aug 31, 2010 at 02:45 AM
A touch has several phases (TouchPhase)...
Began, Moved, Stationary, Ended, Canceled.
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) doStuff();
answered Aug 30, 2010 at 11:54 PM
Unity does most of the work for you here, you need to look at the tapCount of the "Ended" touch (touch.phase = TouchPhase.Ended).
In my testing, I found that if the user pressed and released on the same spot (in under ~1 second) then the tapCount of the "Ended" touch is 1. If they have dragged at all in between pressing and releasing, the tapCount is always 0. Also if they press but hold on the spot for over a second and then release, the tapCount is also 0.
If the maximum tap duration of around 1 second is too long, you'd probably need write your own version of this functionality.
answered Jan 18, 2011 at 02:12 PM