Game Manager

Health System

Give any GameObject a health bar. Wire hazards to TakeDamage(), wire onDeath to a restart or respawn — the manager handles everything in between. Works for players, enemies, and destructible objects.

Damage, healing, and death events
Low health threshold warning
Built-in health bar with gradient
Persists health between scenes

Getting started

Minimal setup

Four steps. The bar and text UI are optional — the events are all you actually need.

⚠️
TakeDamage() ignores calls after death
Once health reaches zero, TakeDamage() does nothing — onDeath fires exactly once. This prevents multiple death triggers stacking up when the player touches several hazards simultaneously. Call FullHeal() or SetHealth() to revive.

Wiring behavior

Events

Wire these to any function. Every gameplay consequence of a health change should live in an event, not in code.

EventParametersWhen it fires
onHealthChangedint current, int maxEvery time health changes (damage or heal). Wire to a custom GameUIManager display or any value-driven effect.
onDamageReceivedAny time damage is taken. Wire to a hurt sound, screen flash, or camera shake.
onHealthGainedAny time health is restored. Wire to a heal sound or visual effect.
onLowHealthReachedFires once when health drops to or below the Low Health Threshold. Wire to a warning music sting or red vignette. Default threshold: 25.
onLowHealthRecoveredFires once when health recovers above the threshold. Wire to cancel the warning effect.
onDeathFires when health reaches zero. Wire to restart, respawn, or game-over screen.
onRevivedFires when health is set above zero after death. Wire to revival effects.

Display options

Built-in UI

Enable Show UI and/or Show Bar to get a self-contained display with no Canvas setup required. Both can be active at the same time.

Show UI
Text display
Shows "HP: 75 / 100" (or just "HP: 75" with Show Max unchecked). Position it anywhere on screen with the Text Position field (top-left origin). Customize label prefix, font size, color, and animation (Punch Scale or Fade Flash on each hit).
Show Bar
Fill bar
A horizontal health bar with a gradient that transitions red → yellow → green by default. Set position and size independently from the text. The bar animates smoothly by default — disable Animate Bar for instant jumps.
💡
Using an external HUD instead?
If you have a Canvas already set up, wire onHealthChanged to GameUIManager's value display instead of using Show UI. Don't use both — they'll stack and create duplicate displays. See the UI Implementation guide for details.

Common patterns

Recipes

Player health with restart
The most common setup
Max Health100
Low Threshold25
Show Bartrue
Hazard → TakeDamage(10)
onDeath → ActionRestartScene.RestartCurrentScene()
Player health with respawn
Use with checkpoints
Persist Across Scenestrue
On RestartReset To Default
onDeath → ActionRespawnPlayer.RespawnToCheckpoint()
onDeath → FullHeal() (after a short delay)
Enemy with death event
Attach to the enemy GameObject
Max Health30
Show Bartrue
Projectile → TakeDamage(10)
onDeath → SetActive(false) or Destroy
onDeath → GameCollectionManager.Increment(1)
Low health warning
Danger zone feedback
Low Threshold25
onLowHealthReached → Play warning music sting
onLowHealthReached → Enable red vignette overlay
onLowHealthRecovered → Disable vignette overlay

Inspector reference

All fields

FieldDefaultWhat it does
Max Health100Maximum health value. TakeDamage and Heal are both clamped to this range.
Current Health100Starting health. Can be set below Max Health to start damaged.
Low Health Threshold25When health drops to this value or below, onLowHealthReached fires.
Persist Across ScenesfalseSaves current health to carry over on scene load. Add the manager to each scene — only the value travels.
On RestartReset To DefaultWhen RestartScene() is called: Reset To Default returns to the Inspector starting value; Keep Value preserves current health.
Show UIfalseCreates a text display ("HP: 75 / 100") at runtime. Customizable prefix, position, font size, color.
Show Max In TexttrueShows "HP: 75 / 100" when on, "HP: 75" when off.
Value AnimationPunch ScaleAnimation on the text each time health changes: None, Punch Scale, or Fade Flash.
Show BarfalseCreates a fill bar at runtime. Bar color tracks the gradient (red → yellow → green by default).
Bar Gradientred→yellow→greenColor at each health percentage. Edit in the Inspector gradient editor to match your art style.
Animate BartrueSmoothly animates bar fill changes. Disable for instant updates.
Public MethodParameterWhat it does
TakeDamage()int amountReduces health by amount. Ignored if already dead.
Heal()int amountRestores health by amount, capped at Max Health. Ignored if dead.
FullHeal()Restores health to Max Health. Does not revive from death — use SetHealth(max) for that.
SetHealth()int valueSets health to an exact value. Can revive (if above 0) or kill (if 0).
SetMaxHealth()int valueChanges Max Health at runtime. Useful for upgrades that increase max HP.