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).

Add Component: Glowing Rifts > Modular Weapon > Dual Weapon

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.
_secondaryMagazineMagazineMagazine used by the secondary barrel. Leave empty, or assign the primary magazine, to share ammo.
_primaryMagazineMagazineCached primary magazine.

Inherited Fields

See Weapon for:

  • _barrel, _magazine, _events, _useBuiltInInput
  • shootState, magazine, barrel
  • OnCanceled, _controls

Public Methods

MethodDescription
void SwitchBarrel(Barrel barrel)Sets the active barrel and its magazine, then begins shooting. Called on input trigger, or by your own input when built-in input is disabled.

Input Bindings

InputAction
ShootPrimary.startedSwitches to primary barrel and fires
ShootPrimary.canceledStops firing
ShootSecondary.startedSwitches to secondary barrel and fires
ShootSecondary.canceledStops firing
Reload.startedReloads the active magazine

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