- Home /
 
Mobile device input
Hello,
i created a game and everything works in the unity editor and on PC but the mobile version works incorrectly because of the input.
The player jumps multiple times on 1 touch but i want to let the play jump only one time at every touch.
         if (Input.touchCount > 0) {  // 1 touch = 1 and not higher ? 
             didFlap = true;
             audioWoosh.Play ();
 
 
         }
 
              Answer by Landern · Mar 23, 2015 at 12:47 PM
If this bit of code is in the Update function/method of the scripting, then you will get a true evaluation every frame during the execution of this code. This is because you haven't constrained the logic to how/when it was touched, only if there is a touch during the frame.
Using Input.touches to check to see if it's the first touch and it 'began' would be a good way of isolating the execution.
You may also only want to check for a single touch.
 if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) 
 {
     didFlap = true;
     audioWoosh.Play ();
 }
 
                
                
              Answer by dr3th · Mar 23, 2015 at 04:17 PM
 //FlappyBirds?
         private int touchesSoFar=0;  
         Update
         {
             if (Input.touchCount> touchesSoFar) {
                 touchesSoFar++;
                 didFlap = true;
                 audioWoosh.Play ();
             }
         }
 
              The Flappy bird clone is my first project because it is so simple and all the sprites are available in the internet :D
Your answer
 
             Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to check whether you have swiped upwards on a mobile device - c# 1 Answer
Collision acting weird on mobile with touch input 1 Answer
Input.GetButton not working 1 Answer
Mobile game touch problem (C#) 2 Answers