summaryrefslogtreecommitdiff
path: root/Gun.cs
blob: d9a3532598e23ab9705934e970ac1cbe9b206a95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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);
			}
		}
	}
}