Raycast Barrel
The RaycastBarrel is a hitscan-based barrel implementation. It uses Unity’s Physics.Raycast to instantly detect and damage targets along a line.
Summary
This component:
- Inherits from 
Barrel - Fires an invisible ray to simulate a bullet
 - Detects 
Hitboxcomponents and applies damage - Optionally spawns VFX at the point of impact
 
Fields
| Field | Type | Description | 
|---|---|---|
_range | float | Max distance the ray travels. | 
_layers | LayerMask | Layers that the raycast can interact with. | 
_damagePoints | MinMaxCurve | Range of possible damage values. | 
_impacts | GameObject[] | Prefabs to spawn at impact (e.g., decals or sparks). | 
_OnHit | UnityEvent<Vector3, Vector3> | Invoked on successful hit with impact position and normal. | 
Public Methods
| Method | Description | 
|---|---|
override void Shoot() | Fires a raycast and applies damage to any hit Hitbox. | 
void SpawnImpact(Vector3 point, Vector3 normal) | Instantiates visual effects at the hit location. | 
Behavior
- Evaluates damage using 
MinMaxCurve.Evaluate()with two random values. - Searches for a 
Hitboxon the collider hit by the ray. - If a hitbox is found, applies damage via 
Hitbox.Hurt(DamageData). - Triggers 
OnHitUnityEvent and optional impact prefabs. 
Use Cases
- Rifles, pistols, machine guns
 - Instant-fire weapons like lasers or tasers (visual-only)
 - Sci-fi blasters without travel time
 
Tip
To prevent friendly fire, configure your LayerMask to only include enemy layers.
Note
You can chain custom logic to _OnHit to spawn particles, sounds, or UI effects.