// Update is called once per frame. void Update() { // If the player is grounded... if (player.grounded) { // ... reset the total air dashes allowed. totalAirDashes = airDashTotal; } // Call the SetDashAllowed function to make sure if a dash is allowed. SetDashAllowed(); // If the player is currently dashing... if (player.dashing) { // ... make sure dashing isn't allowed. dashAllowed = false; // Reset the dash timer if the X velocity is 0. if (player.rigidbody.velocity.x == 0) { dashTimer = 0; } // Run the dash timer. if (dashTimer > 0) { dashTimer -= Time.deltaTime; // When the timer is finished... } else { // ... run the cooldown timer. runCooldownTimer = true; // Player isn't dashing anymore, so reset the variable. player.Dash(false); } } // If the cooldown timer is running... if (runCooldownTimer) { // ... make sure dashing isn't allowed. dashAllowed = false; // Run the cooldown timer. if (cooldownTimer > 0) { cooldownTimer -= Time.deltaTime; // When the timer is finished... } else { // ... reset the runCooldownTimer variable. runCooldownTimer = false; // Call the SetDashAllowed function to make sure if a dash is allowed. SetDashAllowed(); } } // If the dash button is pressed and if a dash is allowed... if (Input.GetButtonDown("Dash") && dashAllowed && !player.dashing && !player.crouching && !player.stuckToWall && !player.falling && !player.sliding && !player.onLadder) { // ... perform the dash. dash = true; } }