public void ReceiveDamage(float healthDamage, float hitPoiseDamage, Vector2 hittingColliderPos, Vector2 receivingColliderPos) { if (!alreadyDead) { curHealth -= healthDamage * damageModifier; eRefs.spriteColorFlash.PlayColorFlash(eRefs.eSpriteR); healthBar.AdjustHealthBar(maxHealth, curHealth); Vector2 hitDir = ((Vector2)receivingColliderPos - hittingColliderPos).normalized; // Apply poise damage from the hit to the enemy which can lead to the enemy being stunned. PoiseDamage(hitPoiseDamage, hitDir); // If I die from this hit and im currently in a hit reaction, stop the hit reaction and die. if (curHealth <= 0f) { if (eRefs.mySpriteAnim != null) { eRefs.mySpriteAnim.Stop(); } alreadyDead = true; if (inHitReaction) { StopCoroutine(hitReactionCoroutine); } eRefs.eDeath.DeathSequence(hitDir); return; } } }
private void UpdateHealthBar(float currentHealth, float maxHealth) { if (healthBar == null) return; float ratio = currentHealth / maxHealth; healthBar.AdjustHealthBar(ratio); }