// Returns the amount actually spent, in case firing a full round // would drop us below 0 ammo, you can scale down the last shot. // You could also implement a TrySpend that aborts for insufficient ammo. public int Spend(AmmoType type, int amount) { AmmoEntry held = _inventory[(int)type]; int spend = Mathf.Min(amount, held.currentMag); held.currentMag -= spend; _inventory[(int)type] = held; return(spend); }
public int SyncCurrentMag(AmmoType type) { AmmoEntry held = _inventory[(int)type]; int syncAmount = weaponSelection.weaponSlots[weaponSelection.selectedSlot].gameObject.GetComponentInChildren <GunScript>().currentMag; held.currentMag = syncAmount; _inventory[(int)type] = held; return(syncAmount); }
// Returns amount collected, so you can choose to not consume // pickups if you're already full (ie. return value is zero). public int Collect(AmmoType type, int amount) { AmmoEntry held = _inventory[(int)type]; int collect = Mathf.Min(amount, held.Stockpile - held.currentMag); held.currentMag += collect; _inventory[(int)type] = held; return(collect); }
public int Collect(AmmoType type, int amount) { AmmoEntry held = _inventory[(int)type]; int collect = Mathf.Min(amount, held.maxCapacity - held.stock); held.stock += collect; _inventory[(int)type] = held; return(collect); }
public int Reload(AmmoType type, int amount) { AmmoEntry held = _inventory[(int)type]; int reloadAmount = Mathf.Min(amount, held.Stockpile); held.Stockpile -= reloadAmount; held.currentMag += reloadAmount; _inventory[(int)type] = held; return(reloadAmount); }