Upgradable Weapon
The UpgradableWeapon is a Weapon that can level up. Each level is a Barrel Config that it applies to its barrel, so a pistol can become a triple-shot pistol without swapping prefabs.
Add Component: Glowing Rifts > Modular Weapon > Upgradable Weapon
✅ Ideal For
- Power-ups and pickups
- Roguelite or arcade weapon progression
- Shop upgrades
📐 Inspector Overview
Aside from the Weapon fields, the upgradable weapon adds:
| Field | Description |
|---|---|
| Levels | The barrel config of each level, starting at level 0 |
| Start Level | The level the weapon starts at (0 is the first config in Levels) |
| On Upgraded (Int32) | Invoked after the level changes, with the new level |
⚙️ How It Works
- On
Awake, the weapon applies the config of its Start Level to the barrel. Upgrade()goes up one level and does nothing at the max level.SetLevel(level)switches to any level, clamped to the levels available.- Each level change calls
barrel.ApplyConfigand raises On Upgraded.
Tip
Wire a pickup’s event to Upgrade() to level the weapon up with no code. Use On Upgraded to update the HUD or play a sound.
Tip
To add muzzles as the weapon levels up, hook On Upgraded to a script that calls barrel.SetSpawnPoints.
🧑💻 Scripting
using GlowingRifts.ModularWeaponSystem;
public class UpgradeOnKill : MonoBehaviour
{
[SerializeField] private UpgradableWeapon _weapon;
public void OnEnemyKilled()
{
if (_weapon.level < _weapon.maxLevel)
_weapon.Upgrade();
}
}| Member | Description |
|---|---|
int level | The current level, starting at 0 |
int maxLevel | The highest level, from the number of configs in Levels |
void Upgrade() | Goes up one level |
void SetLevel(int newLevel) | Switches to a level, clamped to the levels available |