protected bool AddAmmoItem(InventoryItemAmmo inventoryItemAmmo, CollectableItem collectableAmmo) { foreach (var a in _ammo) { if (a.Ammo == null) { a.Ammo = inventoryItemAmmo; inventoryItemAmmo.Pickup(collectableAmmo.transform.position); return(true); } } return(false); }
// -------------------------------------------------------------------------------------------- // Name : AddAmmoItem // Desc : Searches for the first available Ammo Mount and assigns the passed ammo to it. // -------------------------------------------------------------------------------------------- protected bool AddAmmoItem(InventoryItemAmmo inventoryItemAmmo, CollectableAmmo collectableAmmo, bool playAudio) { // Search for empty mount on ammo belt for (int i = 0; i < _ammo.Count; i++) { // A free mount is one with no Ammo assigned (.Ammo==null) if (_ammo[i].Ammo == null) { // Store this Ammo type at the mount _ammo[i].Ammo = inventoryItemAmmo; // Copy over instance data _ammo[i].Rounds = collectableAmmo.rounds; // Pickup inventoryItemAmmo.Pickup(collectableAmmo.transform.position, playAudio); // Broadcast that attempt was successful if (_notificationQueue) { _notificationQueue.Enqueue("Added " + inventoryItemAmmo.inventoryName + " to Ammo Belt"); } // Success so return return(true); } } // Broadcast that attempt was NOT successful if (_notificationQueue) { _notificationQueue.Enqueue("Could not pickup " + inventoryItemAmmo.inventoryName + "\nNo room in Ammo Belt"); } return(false); }