private void FixedUpdate() { if (dying) { // count down to death deathTimer += Time.fixedDeltaTime; // Make screen darker Color newColor = pauseFilter.color; newColor.a = deathTimer / timeToDie; pauseFilter.color = newColor; if (deathTimer > timeToDie) { // Die, show score on game over screen tracker.GameOver(score); } } else { if (numMeleeEnemiesTouching > 0) { // If enemies are touching us, take damage every so often meleeDamageTimer += Time.fixedDeltaTime; if (meleeDamageTimer > meleeAttackSpeed) { OnHit(numMeleeEnemiesTouching * meleeAttackDamage); meleeDamageTimer = 0; } } else { meleeDamageTimer = 0; } // We take control away from player when attacking // There's a rare bug where it doesn't come back, so also we have a timer to reset after 2 seconds if (!controlEnabled) { controlTimer += Time.fixedDeltaTime; if (controlTimer > controlMaxTime) { controlEnabled = true; controlTimer = 0; } } else { controlTimer = 0; } if (dashing) { dashTimer += Time.fixedDeltaTime; // Dash and do damage while we're dashing Dash(); Attack(dashCollider, dashDamage); // fade out sound if halfway through if (dashTimer / dashMaxTime > 0.5f) { audioMain.volume = Mathf.Lerp(mainVolume, 0, dashTimer / dashMaxTime); } if (dashTimer > dashMaxTime) { // Stop dashing, reset animation system dashing = false; UpdateSpeed(); dashTimer = 0; animator.enabled = false; animator.speed = 1.0f; animator.enabled = true; controlEnabled = true; audioMain.Stop(); audioMain.volume = mainVolume; } } else { dashTimer = 0; } } }