summaryrefslogtreecommitdiff
path: root/GameCode/RotatingShooter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'GameCode/RotatingShooter.cs')
-rw-r--r--GameCode/RotatingShooter.cs69
1 files changed, 69 insertions, 0 deletions
diff --git a/GameCode/RotatingShooter.cs b/GameCode/RotatingShooter.cs
new file mode 100644
index 0000000..cdeef51
--- /dev/null
+++ b/GameCode/RotatingShooter.cs
@@ -0,0 +1,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);
+ }
+ }
+}