• 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 /
avatar image
0
Question by marcool1251 · Jul 10, 2018 at 09:28 PM · touchtouch controlstouchphasefingertouchcount

two finger touch always detects one finger touch first

I have two if statements in my update loop. One for a single finger touch and another for a two finger touch. With one finger I am placing and dragging a gameobject. Then with two fingers in a pinch motion, I am scaling the gameobject. The problem is that when I try to touch the screen with two fingers, I usually trigger the one finger function first, causing me to accidentally place the gameobject before being able to scale it.

This script handles the single finger touch. I have a separate script that handles the two finger touch actions.


The only way to prevent this is to touch the screen with both fingers at the exact same time. How can I add some room for error so that when trying to touch the screen with two fingers, even if one finger touches the screen slightly before the other, the one finger action isn't executed? Thank you.

  if (Input.touchCount > 1 && m_HitTransform != null)
             {
                 twoFingers = true;
             }
 
             else if (Input.touchCount == 1 && m_HitTransform != null && twoFingers == false)
             {
 
                 var touch = Input.GetTouch(0);
       
                 if (touch.phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(0))
                 {
                     //code to place and drag gameobject
                 }
             }
 
 
             if (Input.touchCount == 0 && m_HitTransform != null) //no touches
             {
                 twoFingers = false;
             }
            
         } 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Acazied · Apr 28, 2020 at 12:37 AM

yes this is how unity touch detecting works . so i made a little hack, you can create a short time interval if the player taps with two fingers before the time interval then start the twofingertap function else start the one finger tap. here is the script

         bool OneFingerTap;
         float TimerOne;
         float timerInterval = 0.1f; //the more you decrease it the more accurate it gets 
      void Update(){   
         if(OneFingerTap && (TimerOne + timerInterval <= Time.time)){
             HandleOneTapMovement();
             
             OneFingerTap = false;
         }
                 //if there are any touches currently
                 if(Input.touchCount > 0)
                 {
                     // get the first one
                     Touch firstTouch = Input.GetTouch(0);
          
                   //two touches detected
                     if(Input.touchCount == 2){
                         Touch secondTouch = Input.GetTouch(1);
                         if (firstTouch.phase == TouchPhase.Began || secondTouch.phase == TouchPhase.Began){
                          HandleTwoFingerMovement();
                          OneFingerTap = false; 
                         }   
                     }
                     //if Only one touch detected
                     else (firstTouch.phase == TouchPhase.Began)
                     {  
                             TimerOne =Time.time;
                             OneFingerTap = true;
                     }
                 }
      }   
                   HandleOneTapMovement(){
                       //one tap function
                   }
         
                   HandleTwoFingerMovement(){
                       //two tap function
                   }
         
     
     
     
     
     
 

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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

112 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

check touch position 2 Answers

Unity Touch Help! 0 Answers

player moving on the x axis with the finger does not work 0 Answers

Touch phase is moved when touch pressure changed 0 Answers

Input.touchCount returning wrong number 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