Hitbox
Hitbox connects a collider to a Health. It requires a Collider on the same GameObject and finds the Health on itself or a parent on Awake.
Fields
| Field | Type | Description |
|---|---|---|
_damageMultiplier | float | Multiplier applied to damage when this hitbox is hurt. |
onHit | UnityEvent<DamageData> | Invoked when this hitbox is hurt, with the damage after the multiplier. |
Properties
| Property | Type | Description |
|---|---|---|
hitCollider | Collider | The collider on this hitbox, cached on Awake. |
Methods
| Method | Description |
|---|---|
void Hurt(DamageData damage) | Multiplies the damage, sends it to the Health (if any), then invokes onHit. Does nothing while the component is disabled. |
Example
using GlowingRifts.ModularHealthSystem;
void OnCollisionEnter(Collision collision)
{
if (!collision.collider.TryGetComponent(out Hitbox hitbox)) return;
ContactPoint contact = collision.GetContact(0);
hitbox.Hurt(new DamageData
{
damagePoints = 20f,
hitPoint = contact.point,
hitNormal = contact.normal,
instigator = gameObject,
});
}Tip
Always damage through a hitbox rather than calling Health.Hurt directly, so multipliers and hit events apply.