Health Component

The Health component is a simple script used to give any object in the game a health value. It is meant to be placed on the root GameObject of the entity (such as a player, enemy, or destructible object).

Note

Health, Hitbox, DamageData and the health modifiers come from the Modular Health System, which ships with the weapon system. They live in the GlowingRifts.ModularHealthSystem namespace.

Warning

A Hitbox componenet is required to make the health function on the object

❤️ Purpose

This component manages:

  • A numeric health value
  • Health change and death notifications via UnityEvents
  • Healing, killing and resetting health
  • Health modifiers that change or block incoming damage

🧱 Setup Instructions

  1. Attach the Health script to the root of your object.
  2. Optionally hook into the On Health Changed event to update health bars, trigger effects, or run custom logic.
  3. Add a hitbox component anywhere in the hieratchy where there is a collider

📐 Inspector Overview

FieldDescription
HealthThe starting health. It also becomes the maximum health
Destroy On DeathDestroy the GameObject when health reaches zero. Disable it to handle death yourself, for example to respawn players
On Health Changed (Single)Triggered when health is updated, with the health from 0 to 1. Useful for linking to UI elements like sliders or images.
On Death (DamageData)Triggered once when health reaches zero, with the damage that caused the death

Tip

You can use the event On Health Changed to control UI and sounds

🛡️ Health Modifiers

Health modifiers are components added next to Health on the same GameObject. While enabled, they see every incoming hit before it is applied and can change or block it.

ModifierWhat it does
InvincibilityBlocks all damage while the component is enabled. Raises On Invincibility Started and On Invincibility Stopped when it is enabled and disabled

Tip

Enable Invincibility for a couple of seconds after a player spawns, for example from an animation, to give spawn protection.

🔢 Hitpoint

Hitpoint spawns a floating number prefab (with a TextMeshPro text) facing the main camera. Hook the hitbox’s On Hit to Hitpoint.ShowDamage to show damage numbers, or call ShowText("+25") to show any text, for example when a pickup is collected.

💥 Contact Damage

Add ContactDamage to an object with a trigger collider to hurt any Hitbox that enters it, by its Damage value. Useful for spikes, lava, or enemies that hurt on touch.

🎁 Pickups

Pickup is the base for items collected on touch, such as health packs. A pickup needs a trigger collider, raises On Collected with the collector, and is destroyed once collected. See the Health scripting reference to write your own.

✅ Ideal For

  • Enemies
  • Players
  • Destructible props or objects
  • Boss fights