Health (base class)

Inspector Fields

FieldTypeDescription
_statStatThe Stat asset this health system tracks — used to look up the stat-effect receiver.
maxHealthintMaximum hit points for this character.
impactSoundAudioClipPlayed when damage is successfully applied.
blockSoundAudioClipPlayed when an attack is blocked instead of dealt.
dieSoundAudioClipPlayed when the character dies.

Properties

PropertyTypeDescription
maxHealthintMaximum hit points.
currentHealthintCurrent hit points remaining.
isDeadboolWhether the character is currently dead.
valueint (get/set)Alias for currentHealth, clamped to [0, maxHealth].

Methods

MethodDescription
Initialize(ExecutionContext context)Resets health to maxHealth and fires OnInitialize. Called automatically at level start.
ApplyDamage(int damage, bool applyDefense = true, bool ignoreBlocking = false)Reduces health by damage after subtracting defense (when applyDefense is true) and checking block state. Fires OnDamageApplied on a hit or OnDamageBlocked when blocked. Triggers Die() if health reaches zero.
Heal(int amount)Increases health by amount, clamped to maxHealth. Fires OnHealthUpdated.
SetHealth(int health)Sets current health to an exact value, clamped to [0, maxHealth]. Fires OnHealthUpdated and triggers Die() if the result is zero.
Kill()Instantly kills the character by calling SetHealth(0).

Events

EventSignatureDescription
OnInitializeAction<int>Fired with the starting health value. Used by the HUD to set up heart/pip counts.
OnHealthUpdatedAction<int>Fired whenever health changes, passing the new total.
OnDamageAppliedAction<int>Fired when damage lands, passing the damage amount.
OnDamageBlockedActionFired when an incoming attack is blocked.
OnDieAction<ExecutionContext>Fired when the character dies, passing the current context. Subscribe here to handle drop logic or level failure.

PlayerHealth

Extends Health with player-specific behaviour. ApplyDamage returns early without reducing health if the player is currently in a blocking pose — playing blockSound instead of impactSound. Die() plays dieSound before delegating to the base implementation.

EnemyHealth

Extends Health with enemy-specific behaviour. ApplyDamage checks the EnemyController's blocking state and factors in the enemy's defense stat. Die() plays the enemy death animation and sound before delegating to the base, which fires OnDie — used by ItemDropper to spawn loot.

ℹ️
Access player health from instructions via ctx.player.health. See ExecutionContext for the full player API.