Show Damage Numbers
๐ฏ Goal
Pop up a floating number every time an object takes damage.
๐งฐ What You Need
HealthHitpoint- A number prefab with a TextMeshPro text
๐ช Steps
Make the number prefab
Create a prefab with a TextMeshPro text on it or on a child. Give it a short animation that floats up and fades out. The package includes one in Examples/Common/Prefabs/Hitpoint.prefab.
Add Hitpoint
Add Add Component > Glowing Rifts > Misc > Hitpoint to the object, assign the prefab to Hitpoint, and set Lifetime to the length of its animation.
Hook it to Health
Hook the Health’s On Damage Data Received to Hitpoint.ShowDamage (dynamic DamageData). The rounded damage then shows at the hit point, from any hitbox on the object. For numbers from a single part, hook that hitbox’s On Hit instead.
Show custom text
Call ShowText with a static string from any event, for example +25 from a pickup’s On Collected, or Blocked from your own code. Text shows at the Hitpoint’s position.
๐ Inspector Settings
| Field | What it does | Set it to |
|---|---|---|
| Lifetime | Seconds before the number is destroyed | The length of the number’s animation, 1 in the examples |
| Hitpoint | Number prefab with a TextMeshPro text | Hitpoint.prefab or your own |
๐งช Example
DS_Duck in the Many Ducks scene has a Hitpoint with Lifetime 1, hooked to its hitbox’s On Hit, so every bullet shows 25. The duck in Simple Duck hooks it to the health’s On Damage Data Received instead.
DS_HealthPickup in the Health Pickup scene shows +25 by hooking On Collected to ShowText.
๐ก Tips
- On Damage Data Received also fires for heals, and
ShowDamageshows their amount too. Use a hitbox’s On Hit if you only want damage. - A hitbox’s On Hit fires even when Invincibility blocks the hit. On Damage Data Received fires only when health actually changes.
ShowDamageignores zero or negative damage. When the damage has no hit point, the number shows at theHitpoint’s position.- The number turns to face the main camera when it spawns. For a different color on heals, use a second
Hitpointwith another prefab.