Health

Health Component

The Health component allows any object to receive and process damage. It must be paired with a Hitbox to function fully in the damage system.

Summary

This component:

  • Stores current and max health
  • Triggers events when health changes
  • Destroys the object when health reaches zero

Fields

FieldTypeDescription
_healthfloatStarting health of the entity. Set via inspector.
_maxHealthfloat (read-only)Maximum health. Initialized to _health at runtime.
OnHealthChangedUnityEvent<float>Invoked when health changes, passing a normalized value from 0 to 1.

Public Methods

MethodDescription
void Hurt(DamageData damageData)Reduces health based on incoming damage. Invokes OnHealthChanged. Calls Kill() if health is zero.
void Kill()Destroys the GameObject and sets health to 0. Override this for custom death behavior.

Usage

Tip

Attach this script to the root object of any prefab you want to be damageable.

Note

Use Hitbox components on colliders to forward damage here.

Warning

Damage must be applied through Hurt() to affect health.

See Also