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
              
 
               
              Your answer