Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by fiersking_unity · Jul 10, 2018 at 11:39 AM · androidswipe

Finger swipe on android that does't work

Hi everyone !

I have a little code that handle swipe gesture on android it works perfectly but sometime it sounds like the move is not "counted" if someone can help it would be great it's my last problem on this project :)

thanks for all !

 if (Input.touches.Length == 1)
             {
 
                 t = Input.GetTouch(0);
 
                 // Swipe/Touch started
                 if (t.phase == TouchPhase.Began && !swipebegan)
                 {
                     swipebegan = true;
                     swipeEnded = false;
                     firstPressPos = t.position;
                     swipeStartTime = Time.time;
 
                     // Swipe/Touch ended
                 }
 
                 else if (t.phase != TouchPhase.Ended && t.phase != TouchPhase.Canceled && !swipeEnded)
                 {
                     if (t.phase == TouchPhase.Moved)
                     {
 
                         gestureDist = (t.position - firstPressPos).magnitude / dpcm;
                         minSwipeLength = 0.5f;
                         //float maxSwipeTime = 10f;
 
                         // float gestureDist = (t.position - firstPressPos).magnitude / dpcm;
                         // float minSwipeLength = 0.5f;
                         // //float maxSwipeTime = 10f;
 
 
                         if (gestureDist >= minSwipeLength)
                         {
                           
 
                             swipeEndTime = Time.time;
                             secondPressPos = t.position;
                             currentSwipe = secondPressPos - firstPressPos;
                             swipeVelocity = currentSwipe * (swipeEndTime - swipeStartTime);
 
                             currentSwipe.Normalize();
                             
                             Debug.Log("Normalise : " + currentSwipe);
 
                             if (currentSwipe.x <= 0 && currentSwipe.x >= -0.3f && currentSwipe.y >= 0.1 ||
                                 currentSwipe.x >= 0 && currentSwipe.x <= 0.3f && currentSwipe.y >= 0.1f)
                             {
                            
                                 Manager.CurrentSwipeDir = SwipeMove.Up;
 
                             }
                         
                             else if (currentSwipe.x <= -0.3f && currentSwipe.y <= 0.5f && currentSwipe.y >= 0 ||
                                      currentSwipe.x <= -0.3f && currentSwipe.y >= -0.5f && currentSwipe.y <= 0)
                             {
                                 
                                 Manager.CurrentSwipeDir = SwipeMove.Left;
 
                             }
                             else if (currentSwipe.x >= 0.3f && currentSwipe.y <= 0.5f && currentSwipe.y >= 0 ||
                                      currentSwipe.x >= 0.3f && currentSwipe.y >= -0.5f && currentSwipe.y <= 0)
                             {
 
                              
                                 Manager.CurrentSwipeDir = SwipeMove.Right;
 
                             }
                             else if (currentSwipe.x < -0.3f && currentSwipe.y <= 0.9f && currentSwipe.y > 0.4f
                                     )
                             {
                            
                                 Manager.CurrentSwipeDir = SwipeMove.UpLeft;
 
                             }
                             else if (currentSwipe.x > 0.3f && currentSwipe.y <= 0.9f && currentSwipe.y > 0.4f)
                             {
                                
                                 Manager.CurrentSwipeDir = SwipeMove.UpRight;
 
                             }
                             else if (currentSwipe.x <= -0.3f && currentSwipe.y >= -0.9f && currentSwipe.y < -0.4f)
                             {
                              
                                 Manager.CurrentSwipeDir = SwipeMove.DownLeft;
 
                             }
                             else if (currentSwipe.x >= 0.3f && currentSwipe.y >= -0.9f && currentSwipe.y < -0.4f)
                             {
                                
                                 Manager.CurrentSwipeDir = SwipeMove.DownRight;
 
                             }
                             else Manager.CurrentSwipeDir = SwipeMove.None;
 
                             swipeEnded = true;
                             swipebegan = false;
                             t.phase = TouchPhase.Canceled;
 
 
                         }
 
                     }
                 }
                 else if (t.phase == TouchPhase.Ended)
                 {
 
                     float gestureTime = Time.time - swipeStartTime;
                     float gestureDist = (t.position - firstPressPos).magnitude / dpcm;
                     float minSwipeLength = .5f;
                     if (gestureDist < minSwipeLength && !swipeEnded || gestureTime < 0.22f && !swipeEnded)
                     {
                         //its a tap
 
                         swipeVelocity.x = 0;
                         swipeVelocity.y = 0;
                         //trying to send back simple tap
 
                         swipeEnded = true;
                         swipebegan = false;
                         t.phase = TouchPhase.Canceled;
                  
                         Manager.CurrentSwipeDir = SwipeMove.Tap;
 
                     }
 
                 }
      
             }
             else Manager.CurrentSwipeDir = SwipeMove.None;
 
         }





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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

255 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 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 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

How to detect a swipe in ANY direction? 1 Answer

Unity 5 Movement swipe to left and right and up and down 0 Answers

How to change this script so that I can swipe up to jump and swipe down to come down on a touch device? 0 Answers

How can i move just one object ? 0 Answers

swipe manager sometime ignore swipe ? 1 Answer


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