• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
2
Question by anilgautam · Aug 11, 2017 at 07:32 AM · touchdouble-tap

How to detect Double Tap in Android

Hello All

I need some code to detect double tap?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

12 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by Seth-Bergman · Dec 26, 2012 at 11:34 AM

You could search harder...

http://docs.unity3d.com/Documentation/ScriptReference/Touch-tapCount.html

as in:

 for(touch in Input.touches){
 if(touch.tapCount == 2)
 //DoSomething();
 }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vandell · Oct 22, 2013 at 01:08 PM 1
Share

Unfortunately, it doesn't work on Android.From the docs:

tapCount The iPhone/iPad screen is able to distinguish quick finger taps by the user. This counter will let you know how many times the user has tapped the screen without moving a finger to the sides. Android devices do not count number of taps, this field is always 1.

avatar image muhammadtahiriqbal Vandell · Feb 19, 2016 at 03:46 PM 0
Share

so how we can do that

avatar image
0

Answer by haim96 · Oct 22, 2013 at 01:14 PM

i'm using EasyTouch and it works great on android. check there gestures list they can handle (note On_DoubleTap...) http://www.blitz3dfr.com/Doc/ET3/class_easy_touch.html

just to make it clear, i'm not related to them... only suggest the as solution. :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vandell · Oct 22, 2013 at 02:34 PM 0
Share

Thank you for the suggestion. In this time I'm checking the deltaTime from the touches. But we are thinking in buying a gesture plugin :D

avatar image
0

Answer by jim_burger · Nov 24, 2013 at 08:04 AM

As Vandell suggests, tracking your own touches is the go.

For quick code sample - Check the Joystick.js file in the mobile standard assets. In a nutshell:

  • Set a time window - say avg. human reaction time

  • Store your own script level scoped 'tapCount' variable

  • In update, on each tap, test if this tap occurred within the time window, if yes, tapCount++

From Joystick.js

     if ( tapTimeWindow > 0 ) {
         tapTimeWindow -= Time.deltaTime;
     }
     else {
         tapCount = 0;
     }
     if ( tapTimeWindow > 0 )
       tapCount++;
     else
     {
       tapCount = 1;
       tapTimeWindow = tapTimeDelta;
     }

HTH

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
10

Answer by Bouzy · Feb 15, 2017 at 08:40 PM

I know this post i dead. But for the people still looking for an awnser, this is my shot at it. Im am still a beginner so gime me some feedback.

 public class JumpTowardsTap : MonoBehaviour {
 
     int TapCount;
     public float MaxDubbleTapTime;
     float NewTime;
 
     void Start () {
         TapCount = 0;
     }
 
     void Update () {
 if (Input.touchCount == 1) {
             Touch touch = Input.GetTouch (0);
             
             if (touch.phase == TouchPhase.Ended) {
                 TapCount += 1;
             }
 
             if (TapCount == 1) {
                 
                 NewTime = Time.time + MaxDubbleTapTime;
             }else if(TapCount == 2 && Time.time <= NewTime){
                 
                 //Whatever you want after a dubble tap    
                 print ("Dubble tap");
 
                     
                 TapCount = 0;
             }
 
         }
         if (Time.time > NewTime) {
             TapCount = 0;
         }
     }
 }
 




Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
5

Answer by pedrampk · Jul 13, 2018 at 06:26 PM

bellow function works well:

 public static bool IsDoubleTap(){
         bool result = false;
         float MaxTimeWait = 1;
         float VariancePosition = 1;
 
         if( Input.touchCount == 1  && Input.GetTouch(0).phase == TouchPhase.Began)
         {
             float DeltaTime = Input.GetTouch (0).deltaTime;
             float DeltaPositionLenght=Input.GetTouch (0).deltaPosition.magnitude;
 
             if ( DeltaTime> 0 && DeltaTime < MaxTimeWait && DeltaPositionLenght < VariancePosition)
                 result = true;                
         }
         return result;
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brother_77 · Feb 01 at 07:07 PM 0
Share

The code looks good, but for some reason it registers a double tap on the first touch?

  • 1
  • 2
  • 3
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hold touch button Unity Javascript 1 Answer

Control two objects simultaneously using touch controls. 1 Answer

Which gameObject is touched when touch at overlap gameObjects? 1 Answer

UnityEngineCameraBindings.gen.cs throwing a NullReferenceException when using the Camera.ScreenToWorldPoint() Method. 1 Answer

Touch.deltaPosition.magnitude in Unity Remote differs from Android build... why? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges