public void Fire() { if (!weaponIsEquiped) { return; } pulledTrigger = true; crossHair.AddSpread(10); // Handle ammo and reloading if (currentWeaponMagAmmo > 1) { currentWeaponMagAmmo--; } else { currentWeaponMagAmmo--; anim.SetBool("NoAmmo", true); } currentWeapon.currentWeaponMagAmmo = currentWeaponMagAmmo; // Handle raycasting middleScreenRay = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); // Rotate fire direction by spread. if (!currentWeapon.scopeSniper || !aim) { middleScreenRay.direction = Quaternion.AngleAxis(Random.Range(-spread, spread), new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), 0)) * camera.forward; } else { middleScreenRay.direction = Quaternion.AngleAxis(Random.Range(-spread, spread), new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), 0)) * currentWeapon.scopeCamera.transform.forward; } muzzleFlash = !currentWeapon.silenced ? currentWeapon.muzzleFlash : currentWeapon.silencedMuzzleFlash; objPooler.SpawnFromPool(muzzleFlash, weaponMuzzle.rotation, Vector3.zero, weaponMuzzle); if (Physics.Raycast(middleScreenRay, out RaycastHit hit, notPlayerOrInteractible)) { Vector2 hitmarkOffset = currentWeapon.scopeSniper && aim ? sniperScopeOffset : Vector2.zero; objPooler.SpawnFromPool(bulletImpact, hit.point, Quaternion.identity); if (hit.transform.tag == "Enemy") { objPooler.SpawnFromPool("UI Hit Mark", playerCamera.WorldToScreenPoint(hit.point) + transform.up * hitmarkOffset.y + transform.right * hitmarkOffset.x, Quaternion.identity); } } UIManager.instance.SetAmmoCounter(currentWeapon.mainWeapon, currentWeaponMagAmmo, reservedAmmo); }