using UnityEngine; public class Gun : MonoBehaviour { public GameObject projectile; public float rateOfFire = 0.1f; public bool auto = true; public int bulletsInMag = 30; public float reloadTime = 0.5f; public float ADSFOV = 60f; [HideInInspector] public Rigidbody rig; private Transform shootPosition; private Recoil recoil; private AddScreenShake shake; private float counter; public float extraSpread; public float addForceToAllSpawnedRigs; private ParticleSystem part; private GunSFX sfx; private void Start() { rig = GetComponent(); sfx = GetComponent(); recoil = GetComponent(); shake = GetComponent(); shootPosition = GetComponentInChildren().transform; part = GetComponentInChildren(); } private void Update() { counter += Time.deltaTime; } public void Shoot(Transform shooter, bool ADS) { if (counter < rateOfFire) { return; } counter = 0f; if ((bool)part) { part.Play(); } GameObject gameObject = Object.Instantiate(projectile, shootPosition.position, shootPosition.rotation); RandomizeRotation component = gameObject.GetComponent(); if ((bool)component) { component.spread += extraSpread; } SpawnerHolder component2 = gameObject.GetComponent(); if ((bool)component2) { component2.spawner = shooter; } if ((bool)recoil) { recoil.AddRecoil(ADS); } if ((bool)shake) { shake.DoShake(); } if ((bool)sfx) { sfx.PlayShootSound(); } if (addForceToAllSpawnedRigs != 0f) { Rigidbody[] componentsInChildren = gameObject.GetComponentsInChildren(); foreach (Rigidbody rigidbody in componentsInChildren) { rigidbody.AddForce(shootPosition.forward * addForceToAllSpawnedRigs, ForceMode.VelocityChange); } } } }