Laser Barrel
The LaserBarrel is a type of Barrel that simulates continuous beam fire using a LineRenderer. It can apply damage to nearby targets, visually curves the beam, and supports a wind-up time before activation.
Summary
This component:
- Uses a spline-based beam that updates every frame
 - Applies damage to the nearest 
Hitbox in range - Supports warm-up delay and impact feedback
 - Visually displays the laser using 
LineRenderer 
Fields
| Field | Type | Description | 
|---|
damagePoints | int | Amount of damage applied per hit. | 
_line | LineRenderer | Visual representation of the beam. | 
resolution | int | Number of spline points used for beam smoothness. | 
snapRadius | float | Radius used to detect nearby Hitbox targets. | 
maxLength | float | Max distance of the laser beam. | 
affectedLayer | LayerMask | Defines which layers the beam can affect. | 
windUpTime | float | Time (in seconds) before the laser starts firing. | 
Events
| Event | Description | 
|---|
OnImpact(Vector3) | Invoked every frame with the laser’s impact point. | 
OnWindUp | Invoked once when wind-up starts. | 
Public Methods
| Method | Description | 
|---|
override void StartShooting() | Enables laser beam and starts firing loop. | 
override void StopShooting() | Disables laser beam. | 
override void Shoot() | Applies damage to the closest target in path. | 
override void Prepare(Action callback) | Delays firing based on windUpTime. | 
void SetImpactPosition(Transform target) | Moves a target transform to the laser’s hit point. | 
Internal Logic
- Uses 
Physics.OverlapCapsule to detect targets near the beam path. - Picks the closest valid 
Hitbox within the snapRadius. - Uses a 
CubicSpline to bend the beam between origin and destination. - Runs a coroutine to refresh the laser’s appearance and hit detection every frame.
 
Use Cases
- Energy rifles
 - Mining lasers
 - Continuous fire weapons
 - Tactical scanning beams
 
See Also