2d game needs timer inbetween jumps

My 2d game test to learn C# coding has proved fruitful, except I need a timer inbetween the 3 jumps my player has. link is right here.
thanks for anyone fixing it :smiley:

2 ways to do this.

The first, with just an update loop:

float jumpTimer = 0;
void Update(){
    if(jumpTimer > 0){ //count down the timer
        jumpTimer -= Time.deltaTime;
    }
    else if(jumpTime == 3){ //if the timer is zero and you have jumps, remove them
        jumpTime -= 3;
    }
}

then you have in your fixedUpdate

if(jumpTime == 3 && jumpTimer <= 0){ //only set the jump timer it's currently set to zero
    jumpTimer = 3 //replace this with number of seconds
}

The second way is with a coroutine.

IEnumerator JumpTime(){
    yield return new WaitForSeconds(3);
    jumpTime -= 3;
}

which you call from your if(jumpTime == 3) with

StartCoroutine(JumpTime);

Just make sure you put in a flag that the coroutine is running, otherwise it’ll start a whole bunch of them