public void Update() { canFire = curAmmo > 0 && Time.time > nextFireTime; if (Input.GetMouseButton(0) && canFire) { var camTF = PlayerInstance.MainCameraTransform(); for (int i = 0; i < NumberOfPellets; i++) { Instantiate(BulletPrefab, camTF.position + camTF.forward * 0.4f, camTF.rotation); if (firingSound) { transform.root.GetComponent <AudioSource>().PlayOneShot(firingSound); } } nextFireTime = Time.time + RefireDelay; nextAmmoRegenTime = nextFireTime + AmmoRegenFireDelay; curAmmo -= 1; } else if (UsesAmmoMags && Input.GetKeyDown(KeyCode.R) && curAmmo < MagSize && GameController.AmmoMags > 0) { nextFireTime = Time.time + ReloadDuration; nextAmmoRegenTime = nextFireTime + AmmoRegenFireDelay; curAmmo = MagSize; if (UsesAmmoMags) { GameController.AmmoMags -= 1; } } // ammo regen for the PDW if (AmmoRegenWaitTime > 0 && Time.time > nextAmmoRegenTime && curAmmo < MagSize) { curAmmo += 1; nextAmmoRegenTime = Time.time + AmmoRegenWaitTime; } }