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
| Field | Type | Description |
|---|---|---|
_secondaryBarrel | Barrel | The alternate barrel used for secondary fire. |
_primaryBarrel | Barrel | Cached original barrel used for primary fire. |
Inherited Fields
See Weapon for:
_barrel,_recoil,_configshootState,magazine,barrelOnShootingCanceled,_controls
Public Methods
| Method | Description |
|---|---|
void Start() | Initializes input bindings, barrel references, and equips the weapon. |
Protected Methods
| Method | Description |
|---|---|
void SwitchBarrel(Barrel barrel) | Sets the active barrel and begins shooting. Called on input trigger. |
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 |
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