DualWeapon

The DualWeapon script extends the core Weapon functionality by allowing a second fire mode using a separate barrel. This enables alternate fire weapons (e.g., assault rifle with under-barrel grenade launcher).

Summary

This component:

  • Inherits from Weapon
  • Adds support for secondary fire input
  • Dynamically switches barrels based on player input

Fields

FieldTypeDescription
_secondaryBarrelBarrelThe alternate barrel used for secondary fire.
_primaryBarrelBarrelCached original barrel used for primary fire.

Inherited Fields

See Weapon for:

  • _barrel, _recoil, _config
  • shootState, magazine, barrel
  • OnShootingCanceled, _controls

Public Methods

MethodDescription
void Start()Initializes input bindings, barrel references, and equips the weapon.

Protected Methods

MethodDescription
void SwitchBarrel(Barrel barrel)Sets the active barrel and begins shooting. Called on input trigger.

Input Bindings

InputAction
ShootPrimary.startedSwitches to primary barrel and fires
ShootPrimary.canceledStops firing
ShootSecondary.startedSwitches to secondary barrel and fires
ShootSecondary.canceledStops firing

Use Case Example

This component is ideal for weapons like:

  • A machine gun (primary) with a grenade launcher (secondary)
  • An energy blaster with a charged pulse shot
  • Any weapon requiring primary and secondary fire behavior

See Also