Hitbox
The Hitbox component links a collider to a damage system. It enables per-body-part damage scaling and channels damage to the associated Health component on the parent.
Summary
This component:
- Must be placed on a child GameObject with a
Collider - Multiplies incoming damage by a configurable value
- Sends damage to the parent
Healthcomponent - Emits an
onHitevent when hit
Fields
| Field | Type | Description |
|---|---|---|
damageMultiplier | float | Scales incoming damage. Use for headshots, limbs, etc. (e.g., 2.0 for double damage). |
hitCollider | Collider (read-only) | The collider attached to this hitbox GameObject. |
onHit | UnityEvent<DamageData> | Called every time this hitbox receives damage. |
Public Methods
| Method | Description |
|---|---|
void Hurt(DamageData damage) | Applies damage to the parent Health component, scaled by damageMultiplier. Triggers onHit event. |
Setup Instructions
- Add a
Healthcomponent to the root object of your character or entity. - Add
Hitboxto any child objects that have colliders (e.g., head, torso). - Configure
damageMultiplierper region:- Head:
2.0 - Torso:
1.0 - Limbs:
0.5
- Head:
Example
var damage = new DamageData
{
damagePoints = 20f,
hitPoint = transform.position,
instigator = player,
};
hitbox.Hurt(damage);Note
A Hitbox only relays damage — it does not store health itself.
Tip
Use the onHit event to spawn VFX or trigger impact sounds when a hitbox is struck.
Warning
The parent GameObject must have a Health component for damage to be processed.
See Also Health
DamageData
ProjectileAmmo