// Update is called once per frame. void Update() { // Reset total jumps allowed when not performing a jump and grounded or when on a moving/sinking platform. if (!jump && (player.grounded || player.IsStuckToPlatform()) && ((Mathf.Round(player.rigidbody.velocity.y) == 0) || ((player.OnMovingPlatform() || player.OnSinkingPlatform()) && player.rigidbody.velocity.y == player.GetPlatform().GetComponent <Rigidbody2D>().velocity.y))) { jumps = doubleJumping.totalJumps; } // If the jump button is pressed, jumps are allowed and the player is not dashing, sliding, on a ladder or crouching under an obstacle... if (!jump && Input.GetButtonDown("Jump") && jumps > 0 && !player.dashing && !player.sliding && !player.onLadder && (!player.crouching || (player.crouching && player.AllowedToStandUp()))) { // If the player is grounded... if (player.grounded) { // ... initialize jump. InitJump(); // If the player is not grounded and totalJumps is higher than 1... } else if (doubleJumping.totalJumps > 1) { // ... initialize jump if the Y velocity is inside the double jump window (or when there isn't a window). if (!doubleJumping.jumpWindow || (doubleJumping.jumpWindow && player.rigidbody.velocity.y > doubleJumping.jumpWindowMin && player.rigidbody.velocity.y < doubleJumping.jumpWindowMax)) { doubleJump = true; InitJump(); } } } }