private void UpdateAmmoAmount(int newAmount, TypeOfAmmo typeOfAmmo) { if (currentTypeOfAmmo == typeOfAmmo) { AmmoAmountText.text = newAmount.ToString(); } }
private IEnumerator initialize() { yield return(new WaitForSeconds(0.2f)); currentTypeOfAmmo = TypeOfAmmo.Bullets; ammo = FindObjectOfType <Ammo>(); ammo.OnAmmoAmountChanged.AddListener(UpdateAmmoAmount); UpdateAmmoAmount(ammo.GetAmmoAmount(currentTypeOfAmmo), currentTypeOfAmmo); switcher = FindObjectOfType <WeaponSwitcher>(); switcher.OnWeaponSwitched.AddListener(UpdateAmmoType); UpdateAmmoType(currentTypeOfAmmo); }
public bool AddAmmo(TypeOfAmmo typeOfAmmo, int addedAmount) { var ammoItem = ammoDictionary[typeOfAmmo]; if (ammoItem != null) { var result = ammoItem.AddAmmo(addedAmount); if (result) { OnAmmoAmountChanged?.Invoke(ammoItem.currentAmount, ammoItem.TypeOfAmmo); } return(result); } Debug.LogWarning($"Ammo type {typeOfAmmo} not found."); return(false); }
private void UpdateAmmoType(TypeOfAmmo ammoType) { currentTypeOfAmmo = ammoType; Color typeColor; switch (ammoType) { case TypeOfAmmo.Bullets: typeColor = bulletsColor; break; case TypeOfAmmo.Mana: typeColor = manaColor; break; default: throw new ArgumentOutOfRangeException(nameof(ammoType), ammoType, null); } AmmoTypeText.text = ammoType.ToString(); AmmoTypeText.color = typeColor; AmmoAmountText.color = typeColor; UpdateAmmoAmount(ammo.GetAmmoAmount(currentTypeOfAmmo), currentTypeOfAmmo); }
public int GetAmmoAmount(TypeOfAmmo typeOfAmmo) { return(ammoDictionary[typeOfAmmo]?.currentAmount ?? -1); }