void Update() { if (Input.GetAxis("Fire1") == 1) { ProcessFiring(); } if (previousAmmo != ammo.GetAmmoAmount(ammoType)) { UpdateWeaponUI(); previousAmmo = ammo.GetAmmoAmount(ammoType); } }
private void DisplayAmmo() { int currentAmmoL = ammoSlot.GetCurrentAmmo(ammoType); int currentAmmoR = ammoSlot.GetAmmoAmount(ammoType); ammoText.text = "Ammo " + currentAmmoL.ToString() + '/' + currentAmmoR.ToString(); }
void Update() { if (Input.GetMouseButtonDown(0) && ammoSlot.GetAmmoAmount(ammoType) > 0 && canShoot) { StartCoroutine(Shoot()); } }
void Start() { FPSCamera = Camera.main; ammo = GetComponentInParent <Ammo>(); animator = GetComponent <Animator>(); playerUIHandler = FindObjectOfType <PlayerUIHandler>(); UpdateWeaponUI(); previousAmmo = ammo.GetAmmoAmount(ammoType); }
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); }
IEnumerator Shoot() { canShoot = false; if (ammoSlot.GetAmmoAmount(ammoType) > 0) { muzzleFlashFx.Play(); RaycastHit hit; if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, range)) { GameObject impact = Instantiate(hitFx, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impact, 0.1f); EnemyHealth target = hit.transform.GetComponent <EnemyHealth>(); if (target) { target.TakeDamage(attackPower); } } ammoSlot.ReduceAmmoAmount(ammoType); } yield return(new WaitForSeconds(shotDelay)); canShoot = true; }
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); }
private void DisplayAmmo() { ammoText.text = "Ammo : " + myAmmo.GetAmmoAmount(ammoType).ToString(); }