From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- Gun.cs | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Gun.cs (limited to 'Gun.cs') diff --git a/Gun.cs b/Gun.cs new file mode 100644 index 0000000..d9a3532 --- /dev/null +++ b/Gun.cs @@ -0,0 +1,94 @@ +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); + } + } + } +} -- cgit v1.1-26-g67d0