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

FieldTypeDescription
_damageMultiplierfloatMultiplier applied to damage when this hitbox is hurt.
onHitUnityEvent<DamageData>Invoked when this hitbox is hurt, with the damage after the multiplier.

Properties

PropertyTypeDescription
hitColliderColliderThe collider on this hitbox, cached on Awake.

Methods

MethodDescription
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.