Barrel
The Barrel
is the core extension of a weapon that defines how it shoots. It controls spawn points, shooting modes, firing rate, and triggers all visual/audio cues via UnityEvents.
Warning
Barrel
is an abstract base class. Do not use it directly — use a subclass like RaycastBarrel
or ProjectileBarrel
.
Summary
This component:
- Defines spawn points for bullets or effects
- Handles bullet count, fire rate, and shooting mode
- Fires UnityEvents on start, shot, and end
- Loops through multiple spawn points if defined
- Meant to be extended for specific firing behavior
Fields
Field | Type | Description |
---|---|---|
_spawnPoints | List<Transform> | List of locations used to spawn projectiles or traces. |
magazine | Magazine | The ammo container assigned to this barrel. |
weapon | Weapon | The owning weapon. Automatically assigned during setup. |
bulletsFired | int | Number of bullets or shots fired per trigger. |
shootingMode | ShootingMode | How the barrel fires (auto, semi, burst). |
fireRate | float | How many times per second the barrel can fire. |
Unity Events
Event | Description |
---|---|
_OnStartShooting | Called when the player starts shooting. |
_OnShot | Called when a bullet/projectile is fired. |
_OnEndShooting | Called when the player stops shooting. |
Methods
Method | Description |
---|---|
virtual void StartShooting() | Triggers _OnStartShooting . Override for custom behavior. |
virtual void StopShooting() | Triggers _OnEndShooting . Override for custom behavior. |
virtual void Shoot() | Called when it’s time to fire. Override to implement projectile or ray logic. |
virtual void Prepare(Action callback) | Called before Shoot() . Use this for warmups, charge, or animations. |
Spawn Point Behavior
If multiple _spawnPoints
are assigned, the barrel cycles through them in order for each shot, useful for multi-barrel weapons or offset spread.
Usage Example
Do not use Barrel
directly. Instead:
public class RaycastBarrel : Barrel
{
public override void Shoot()
{
base.Shoot();
// Perform raycast logic here
}
}