public void purchaseUpgrade(string gunName) { WeaponType weapon = weapons.equippedWeapons.Find(w => w.name == gunName); if (weapon == null) { Debug.LogError("Gun is not equipped"); return; } if (rm.getEnergy() >= weapon.upgradeCost) { rm.useEnergy(weapon.upgradeCost); weapon.upgrade(); } }