Getting Started
🧠 How It Works
Damage flows through three pieces:
flowchart LR
A[Attack] -->|DamageData| B(Hitbox)
B -->|x Damage Multiplier| C(Health)
C --> D{Health Modifiers}
D -->|damage left| E[Health reduced]
- DamageData describes one hit: the amount, where it hit, the surface normal and who caused it.
- Hitbox sits on a collider. It scales the damage by its multiplier and forwards it to the
Healthon the same object or a parent. - Health lets its modifiers change or block the damage, then applies what’s left and raises its events.
All scripts are in the GlowingRifts.ModularHealthSystem namespace.
📦 Installation
- Import the package from the Unity Asset Store.
- The package is installed under
Assets/Glowing Rifts/Modular Health System. - TextMeshPro is needed for
Hitpointdamage numbers. Import its essentials if Unity asks. - Add the components from Add Component > Glowing Rifts > Modular Health (
Health,Hitbox,Invincibility,Health Pickup) and Glowing Rifts > Misc (Hitpoint,Sound Generator,Spawnable Effect,SelfDestruct).
📦 Ready-Made Prefabs
The Health folder has three prefabs you can drag straight into a scene:
| Prefab | What it is |
|---|---|
Health | A sphere with Health (100) and a Hitbox |
Damage | A sphere that takes 100 health from anything it touches, every time |
Health Pickup | A sphere that gives 25 health to an object on the Player layer, then disappears |
🧱 Your First Damageable Object
Add Health
Select the root of your object (a player, an enemy, a crate) and add the Health component. Set Health to its starting and maximum health.
Add a Hitbox
Add Hitbox to every GameObject with a collider that should take damage. It finds the Health on itself or a parent automatically. If the object has a single collider next to Health, you can skip this step: Health adds a Hitbox with multiplier 1 when it finds none.
Hook the events
Use On Health Changed to drive a health bar (it passes health from 0 to 1), On Damage Data Received to show damage numbers, and On Death to play an effect or end the game.
Deal damage
Call hitbox.Hurt(...) from your attack, or drop a Health Pickup with a negative Amount in the scene to test it.
using GlowingRifts.ModularHealthSystem;
if (hit.collider.TryGetComponent(out Hitbox hitbox))
{
hitbox.Hurt(new DamageData
{
damagePoints = 25f,
hitPoint = hit.point,
hitNormal = hit.normal,
instigator = gameObject,
});
}Tip
Turn off Destroy On Death on players, then call ResetHealth() when they respawn.