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.
Four steps. The bar and text UI are optional — the events are all you actually need.
GameHealthManager. Set Max Health and Current Health to your starting value (e.g. 100).InputTriggerZone with tag Player. Wire On Trigger Enter → GameHealthManager.TakeDamage(10). The int parameter is the damage amount.GameHealthManager and find the onDeath event. Wire it to ActionRestartScene.RestartCurrentScene() or ActionRespawnPlayer.RespawnToCheckpoint().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.Wire these to any function. Every gameplay consequence of a health change should live in an event, not in code.
| Event | Parameters | When it fires |
|---|---|---|
| onHealthChanged | int current, int max | Every time health changes (damage or heal). Wire to a custom GameUIManager display or any value-driven effect. |
| onDamageReceived | — | Any time damage is taken. Wire to a hurt sound, screen flash, or camera shake. |
| onHealthGained | — | Any time health is restored. Wire to a heal sound or visual effect. |
| onLowHealthReached | — | Fires once when health drops to or below the Low Health Threshold. Wire to a warning music sting or red vignette. Default threshold: 25. |
| onLowHealthRecovered | — | Fires once when health recovers above the threshold. Wire to cancel the warning effect. |
| onDeath | — | Fires when health reaches zero. Wire to restart, respawn, or game-over screen. |
| onRevived | — | Fires when health is set above zero after death. Wire to revival effects. |
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.
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.| Field | Default | What it does |
|---|---|---|
| Max Health | 100 | Maximum health value. TakeDamage and Heal are both clamped to this range. |
| Current Health | 100 | Starting health. Can be set below Max Health to start damaged. |
| Low Health Threshold | 25 | When health drops to this value or below, onLowHealthReached fires. |
| Persist Across Scenes | false | Saves current health to carry over on scene load. Add the manager to each scene — only the value travels. |
| On Restart | Reset To Default | When RestartScene() is called: Reset To Default returns to the Inspector starting value; Keep Value preserves current health. |
| Show UI | false | Creates a text display ("HP: 75 / 100") at runtime. Customizable prefix, position, font size, color. |
| Show Max In Text | true | Shows "HP: 75 / 100" when on, "HP: 75" when off. |
| Value Animation | Punch Scale | Animation on the text each time health changes: None, Punch Scale, or Fade Flash. |
| Show Bar | false | Creates a fill bar at runtime. Bar color tracks the gradient (red → yellow → green by default). |
| Bar Gradient | red→yellow→green | Color at each health percentage. Edit in the Inspector gradient editor to match your art style. |
| Animate Bar | true | Smoothly animates bar fill changes. Disable for instant updates. |
| Public Method | Parameter | What it does |
|---|---|---|
| TakeDamage() | int amount | Reduces health by amount. Ignored if already dead. |
| Heal() | int amount | Restores 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 value | Sets health to an exact value. Can revive (if above 0) or kill (if 0). |
| SetMaxHealth() | int value | Changes Max Health at runtime. Useful for upgrades that increase max HP. |