Projectile Barrel
The ProjectileBarrel spawns physical projectiles like grenades, rockets, or arrows. It instantiates a ProjectileAmmo prefab, sets its position and rotation, and launches it.
Summary
This component:
- Inherits from
Barrel - Spawns a projectile prefab each time it fires
- Sends damage and ownership data to the projectile
- Optionally exposes projectile instantiation events
Fields
| Field | Type | Description |
|---|---|---|
_projectilePrefab | ProjectileAmmo | Prefab to instantiate and fire. |
projectileEvents.OnProjectileSpawned | UnityEvent<ProjectileAmmo> | Event fired after each projectile is instantiated. |
Public Methods
| Method | Description |
|---|---|
override void Shoot() | Calls base, then spawns one projectile per bullet. |
Private Methods
| Method | Description |
|---|---|
void SpawnBullet(Transform origin) | Instantiates a projectile at origin and launches it. |
Behavior
- Each time the barrel fires,
Shoot()spawnsBulletsFirednewProjectileAmmoinstances. - Each projectile inherits position and rotation from its bullet’s spawn point.
- The
Shoot()method on the projectile receives:- a damage value rolled from the barrel’s
config.damage - the barrel’s
owner(the weapon) as the instigator
- a damage value rolled from the barrel’s
Tip
Use projectileEvents.OnProjectileSpawned to trigger sound effects, animations, or custom tracking logic.
Use Case Examples
- Grenade launchers
- Rocket launchers
- Shotguns using physics projectiles
- Throwable weapons