-fps Shooter- Script Pastebin | Realistic Guns
She studied how actual weapons behave: recoil that kicks the camera up, spread that increases with sustained fire, and ammo that doesn’t magically refill on reload.
// Recoil: add to camera rotation float verticalRecoil = Random.Range(-recoilForce * 0.5f, recoilForce); playerCamera.transform.Rotate(-verticalRecoil, Random.Range(-recoilForce/2, recoilForce/2), 0);
[Header("Effects")] public Camera playerCamera; public ParticleSystem muzzleFlash; public GameObject impactEffect; public AudioSource shootSound; public AudioSource reloadSound; Realistic Guns -fps Shooter- Script Pastebin
using UnityEngine; public class RealisticGun : MonoBehaviour { [Header("Weapon Stats")] public float damage = 35f; public float range = 100f; public float fireRate = 600f; // rounds per minute public int magazineSize = 30; public int currentAmmo; public float reloadTime = 2.5f; private bool isReloading = false;
// Spread calculation currentSpread = Mathf.Min(maxSpread, currentSpread + spreadPerShot); Vector3 spreadOffset = Random.insideUnitSphere * currentSpread; She studied how actual weapons behave: recoil that
System.Collections.IEnumerator Reload() { isReloading = true; reloadSound.Play(); yield return new WaitForSeconds(reloadTime); currentAmmo = magazineSize; isReloading = false; }
// Visual & audio feedback muzzleFlash.Play(); shootSound.Play(); spread that increases with sustained fire
RaycastHit hit; Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0) + spreadOffset * 0.01f);















暂无评论内容