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
| Field | Type | Description |
|---|---|---|
_secondaryBarrel | Barrel | The alternate barrel used for secondary fire. |
_primaryBarrel | Barrel | Cached original barrel used for primary fire. |
_secondaryMagazine | Magazine | Magazine used by the secondary barrel. Leave empty, or assign the primary magazine, to share ammo. |
_primaryMagazine | Magazine | Cached primary magazine. |
Inherited Fields
See Weapon for:
_barrel,_magazine,_events,_useBuiltInInputshootState,magazine,barrelOnCanceled,_controls
Public Methods
| Method | Description |
|---|---|
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
| Input | Action |
|---|---|
ShootPrimary.started | Switches to primary barrel and fires |
ShootPrimary.canceled | Stops firing |
ShootSecondary.started | Switches to secondary barrel and fires |
ShootSecondary.canceled | Stops firing |
Reload.started | Reloads 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