Show Damage Numbers

Show Damage Numbers

๐ŸŽฏ Goal

Pop up a floating number every time an object takes damage.

๐Ÿงฐ What You Need

  • Health
  • Hitpoint
  • 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

FieldWhat it doesSet it to
LifetimeSeconds before the number is destroyedThe length of the number’s animation, 1 in the examples
HitpointNumber prefab with a TextMeshPro textHitpoint.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 ShowDamage shows 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.
  • ShowDamage ignores zero or negative damage. When the damage has no hit point, the number shows at the Hitpoint’s position.
  • The number turns to face the main camera when it spawns. For a different color on heals, use a second Hitpoint with another prefab.

๐Ÿ”— Related