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

FieldTypeDescription
_projectilePrefabProjectileAmmoPrefab to instantiate and fire.
projectileEvents.OnProjectileSpawnedUnityEvent<ProjectileAmmo>Event fired after each projectile is instantiated.

Public Methods

MethodDescription
override void Shoot()Calls base, then spawns one projectile per bullet.

Private Methods

MethodDescription
void SpawnBullet(Transform origin)Instantiates a projectile at origin and launches it.

Behavior

  • Each time the barrel fires, Shoot() spawns BulletsFired new ProjectileAmmo instances.
  • 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

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

See Also