Realistic Guns -fps Shooter- Script Pastebin -
private float nextTimeToFire = 0f; private float originalCameraY;
[Header("Effects")] public Camera playerCamera; public ParticleSystem muzzleFlash; public GameObject impactEffect; public AudioSource shootSound; public AudioSource reloadSound; Realistic Guns -fps Shooter- Script Pastebin
// Shooting if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire && currentAmmo > 0) { nextTimeToFire = Time.time + 60f / fireRate; Shoot(); } private float nextTimeToFire = 0f
System.Collections.IEnumerator Reload() { isReloading = true; reloadSound.Play(); yield return new WaitForSeconds(reloadTime); currentAmmo = magazineSize; isReloading = false; } private float originalCameraY
// Recoil: add to camera rotation float verticalRecoil = Random.Range(-recoilForce * 0.5f, recoilForce); playerCamera.transform.Rotate(-verticalRecoil, Random.Range(-recoilForce/2, recoilForce/2), 0);
// Spread decays over time when not shooting currentSpread = Mathf.Max(0, currentSpread - spreadDecayRate * Time.deltaTime);