summaryrefslogtreecommitdiff
path: root/Gun.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gun.cs')
-rw-r--r--Gun.cs94
1 files changed, 94 insertions, 0 deletions
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<Rigidbody>();
+ sfx = GetComponent<GunSFX>();
+ recoil = GetComponent<Recoil>();
+ shake = GetComponent<AddScreenShake>();
+ shootPosition = GetComponentInChildren<ShootPosition>().transform;
+ part = GetComponentInChildren<ParticleSystem>();
+ }
+
+ 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<RandomizeRotation>();
+ if ((bool)component)
+ {
+ component.spread += extraSpread;
+ }
+ SpawnerHolder component2 = gameObject.GetComponent<SpawnerHolder>();
+ 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<Rigidbody>();
+ foreach (Rigidbody rigidbody in componentsInChildren)
+ {
+ rigidbody.AddForce(shootPosition.forward * addForceToAllSpawnedRigs, ForceMode.VelocityChange);
+ }
+ }
+ }
+}