public override void TakeDamage(int damage) { base.TakeDamage(damage); PlayerData.playerCurrentHealth = currentHealth; playerAnimator.Damaged(); // flinch animation OnPlayerHealthChange(); // broadcast a change in health for the UI }
void Update() { // If the player has just been damaged... if (damaged) { // ... set the colour of the damageImage to the flash colour. damageImage.color = flashColour; anim.Damaged(); } // Otherwise... else { // ... transition the colour back to clear. damageImage.color = Color.Lerp(damageImage.color, Color.clear, flashSpeed * Time.deltaTime); } // Reset the damaged flag. damaged = false; }