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.
damagePointsintDamage value passed to the projectile.
pooledboolOptional field for future pooling logic (not active).
prewarmCountintNumber of projectiles to pre-instantiate if pooling.
OnProjectileSpawnedUnityEvent<ProjectileAmmo>Event fired after the projectile is instantiated.

Public Methods

MethodDescription
override void Shoot()Calls base, instantiates a projectile, and launches it.

Private Methods

MethodDescription
IEnumerator SpawnBullet()Instantiates and sets up the projectile after a frame delay.

Behavior

  • Each time the barrel fires, Shoot() spawns a new ProjectileAmmo instance.
  • The projectile inherits position and rotation from spawnPoint.
  • The Shoot() method on the projectile receives:
    • damagePoints from this barrel
    • GameObject reference of the weapon as the instigator

Tip

Use OnProjectileSpawned to trigger sound effects, animations, or custom tracking logic.

Note

Although pooling fields are defined, pooling is not yet implemented in this version.

Use Case Examples

  • Grenade launchers
  • Rocket launchers
  • Shotguns using physics projectiles
  • Throwable weapons

See Also