something about jump motion by addForce

hi everyone~
i just wrote a simple 2D game like infinite runner,and i got a question about jumpping motion:
i made my game to run on my Android 4.1 mobile device and when i touch the screen ,i use addForce() and Animator.setBool() to make my character jump,here is my code piece:

public void Jump(){
        rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x,0f);
        playerStuff.Anim.SetBool ("Grounded",false);
        rigidbody2D.AddForce (new Vector2(0,playerStuff.JumpForce));
    }

and my code piece for handling input:

    void Update () {
        if(Input.touchCount==1 && Input.GetTouch(0).tapCount==1 ){
            playerController.Jump();
        }
    }

and here the question:
i dont know why ,my character sometimes can jump really really high,but most of the time is normal

The Jump() function is probably executing more than once.

Your ‘if’ statement is ‘true’ for more than one update - your finger might be in contact with the screen for more than 1 single update. If you touch the screen for a quarter of a second, and your game is running at 60 FPS, that means that ‘Jump()’ gets called 60 * 0.25 = 20 times!

You should check the phase of the finger rather than the tap count -

void Update () {
        if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
            playerController.Jump();
        }
    }

oh,you’re right,at first i just tried TouchPhase.Moved,but it didnt work,and according to your explanation,just becase i touch and move on my screen ,it can be detected for more than once anain!
oh ~ you help me twice haha ,thanks:smile::smile: