Jumping Problem

Hello, I am new to unity and was just wondering how I would write out the following in code, “If the space bar is pressed twice” it is for a double jump I am trying to do, I have single jump fine but i want to be able to jump one more time when still in the air. Thanks for any advise!

You can try using this. It may not limit you to exactly 2 jumps before it maxes out. Attach it to the mesh on your 1st or 3rd person controller and make sure there is a rigidbody component. Change the value for jumpForce in the code to set the force applied. Change the value inside the “if” statement at the bottom, to the right of “hit.distance <=‘’”, to the maximum height from the ground that you want the player to be able to use jumping. edit: sorry I just realized you tagged c#. This is in js, I apologize. I’m sure someone can translate, but I wouldn’t have the slightest clue…

    public var jumpForce : float;
    public var hit : RaycastHit;
    public var distanceToGround;
     
    function Update (){

    //finds the distance between the ground and the player
    if (Physics.Raycast (transform.position, -Vector3.up, hit)) {
    distanceToGround = hit.distance;
     
    }
    }
     
    function FixedUpdate(){
     
    //limits jumping
    if (Input.GetKeyDown(KeyCode.Space) && (hit.distance <= .5)){
    rigidbody.AddForce(Vector3.up*jumpForce);
     
    }
    }