summaryrefslogtreecommitdiff
path: root/GameCode/RotatingShooter.cs
blob: cdeef5149913c7289b228c3dba985d00f0afa903 (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
using System.Collections;
using Sirenix.OdinInspector;
using UnityEngine;

public class RotatingShooter : MonoBehaviour
{
	private Gun gun;

	[HideInInspector]
	public float charge;

	public int bulletsToFire = 10;

	private int currentBulletsToFire = 10;

	private float degreesPerBullet;

	[FoldoutGroup("Weird settings", 0)]
	public bool destroyAfterAttack = true;

	[FoldoutGroup("Weird settings", 0)]
	public bool disableTrailRenderer = true;

	private AttackLevel level;

	private void Start()
	{
		level = GetComponentInParent<AttackLevel>();
		gun = GetComponent<Gun>();
		if (disableTrailRenderer)
		{
			base.transform.root.GetComponentInChildren<TrailRenderer>(includeInactive: true).enabled = false;
		}
	}

	public void Attack()
	{
		currentBulletsToFire = bulletsToFire;
		if ((bool)level)
		{
			currentBulletsToFire = bulletsToFire * level.attackLevel;
		}
		degreesPerBullet = 360f / (float)currentBulletsToFire;
		StartCoroutine(RotateAndShoot());
	}

	private IEnumerator RotateAndShoot()
	{
		int shotsToMake = Mathf.Clamp(Mathf.RoundToInt(0.5f / gun.attackSpeed), 1, 5);
		for (int i = 0; i < shotsToMake; i++)
		{
			for (int num = currentBulletsToFire; num > 0; num--)
			{
				base.transform.localEulerAngles = new Vector3(0f, (float)num * degreesPerBullet, 0f);
				gun.Attack(gun.currentCharge, forceAttack: true);
			}
			if (shotsToMake > i)
			{
				yield return new WaitForSeconds(0.1f);
			}
		}
		base.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
		yield return null;
		if (destroyAfterAttack)
		{
			Object.Destroy(base.transform.root.gameObject);
		}
	}
}