Double jump in a 2D game

I am attempting to give my player a double jump in my 2D game. All the stuff that is in comment form in the script is what I attempted to use to perform my double jump.

void StateInAir()
    {
        HandleHorizontalInput ();

        if (canJump) {
            if (timeHoldingInput < maxJumpBtnHoldTime && Input.GetKey(KeyCode.Space))
            {
                timeHoldingInput += Time.deltaTime;
                GetComponent<Rigidbody2D> ().velocity += new Vector2 (0, thePlayer.JumpAccel ());
//                if(Input.GetKeyUp(KeyCode.Space) && doublejump == true)
//                {
//                    SetState(PlayerStates.ENTER_JUMP);
//                    if (timeHoldingInput < maxJumpBtnHoldTime && Input.GetKey (KeyCode.Space))
//                    {
//                        timeHoldingInput += Time.deltaTime;
//                        GetComponent<Rigidbody2D> ().velocity += new Vector2 (0, thePlayer.JumpAccel ());
//                        doublejump = false;
//                    }
//                }
            }
//            else if( doublejump == true)
//            {
//                timeHoldingInput = 0;
//                doublejump = false;
//            }
            else
            {
                canJump = false;
                //SetState(PlayerStates.IDLE);
            }
        }
        else
        {
            CheckForGround();
            if( onGround)
            {
                HandleLandOnGround();
                doublejump = true;
            }
        }
    }

Well, hard to say what’s wrong with it having all those variables with unknown source/values. :slight_smile:
canJump
maxJumpBtnHoldTime
doublejump
A good start would be to add some Debug.Log statements to see what are the actual values of those variables and if your double jump code does trigger.

Oh sorry. I didn’t add the entire code thinking it would be easier for people to read what I am talking about, I guess not. :slight_smile: Here are my variables. I will try the debug and see what happens.

private enum PlayerStates
    {
        IDLE,
        RUN,
        ENTER_JUMP,
        IN_AIR,

        NUM_STATES
    }
   
    //Exposed Variables
    [SerializeField]
    private float maxJumpBtnHoldTime = 0.28f;
    [SerializeField]
    private float timeHoldingInput = 0.0f;
    [SerializeField]
    private Transform groundCheck;
    [SerializeField]
    private LayerMask walkableLayer;
    [SerializeField]
    private float groundCheckRadius = 0.1f;
    [SerializeField]
    private GameObject spawnPoint;
    //Private Variables
    Player thePlayer;
    PlayerStates curState;
    Dictionary<PlayerStates, Action> fsm = new Dictionary<PlayerStates, Action>();

    private bool canJump = true;
    private bool onGround = false;
    private int healthAmount = 100;
    private int damageAmount= 0;
    private bool doublejump = true;