Barrel Component
The Barrel is the component responsible for handling all firing logic in your modular weapon system. It’s the part of the weapon that defines how bullets are shot: whether hitscan, projectile, or otherwise.
All barrel types inherit from a common base class, allowing for consistent structure and extendability. This page will cover the base barrel features, followed by specific behavior of each subtype.
Caution
The base barrel shares common functionality with the inhereted barrel type, but you can’t add it as a component on it’s own. It was mainly made to provide logic to the child classes.
π§± Base Barrel Features
Regardless of the firing style, all barrels expose the following configuration:
Spawn Points
A list of Transform
points where projectiles or raycasts originate. Multiple spawn points allow for multi-barrel weapons.
Tip
You can place multiple transforms in the prefab and reference them in the list. The barrel will cycle through them shooting a bullet at each point
Note
Having 0 referenced points means that the bullet will shoot from the barrel’s position
Magazine
Reference to a Magazine
component. This allows the barrel to access available ammo
Bullets Fired
Number of bullets fired per trigger pull. Useful for burst or multi-shot mechanics.
Shooting Mode
Defines how the weapon fires:
SemiAutomatic
β fires once per clickBurst
β fires a set of 3 bullets per inputFullAutomatic
β keeps firing while input is held
Fire Rate
Shots per second. Affects how quickly the barrel can shoot again after firing.
Unity Events
These hooks allow for easy integration of animation, VFX, SFX, and additional logic:
- On Start Shooting: Called once when the trigger is pulled (good for animations or initial effects).
- On Shot: Called every time a bullet is fired.
- On End Shooting: Called once when shooting stops (good for looping effects or wind-down animations).
π Other Barrel Types
Weβll cover these in dedicated sections:
Each extends the base functionality with unique mechanics and impact logic.