summaryrefslogtreecommitdiff
path: root/GameCode/DamageOverTime.cs
diff options
context:
space:
mode:
Diffstat (limited to 'GameCode/DamageOverTime.cs')
-rw-r--r--GameCode/DamageOverTime.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/GameCode/DamageOverTime.cs b/GameCode/DamageOverTime.cs
new file mode 100644
index 0000000..c1c6a17
--- /dev/null
+++ b/GameCode/DamageOverTime.cs
@@ -0,0 +1,38 @@
+using System.Collections;
+using Sonigon;
+using UnityEngine;
+
+public class DamageOverTime : MonoBehaviour
+{
+ private HealthHandler health;
+
+ private CharacterData data;
+
+ private void Start()
+ {
+ health = GetComponent<HealthHandler>();
+ data = GetComponent<CharacterData>();
+ }
+
+ public void TakeDamageOverTime(Vector2 damage, Vector2 position, float time, float interval, Color color, SoundEvent soundDamageOverTime, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true)
+ {
+ StartCoroutine(DoDamageOverTime(damage, position, time, interval, color, soundDamageOverTime, damagingWeapon, damagingPlayer, lethal));
+ }
+
+ private IEnumerator DoDamageOverTime(Vector2 damage, Vector2 position, float time, float interval, Color color, SoundEvent soundDamageOverTime, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true)
+ {
+ float damageDealt = 0f;
+ float damageToDeal = damage.magnitude;
+ float dpt = damageToDeal / time * interval;
+ while (damageDealt < damageToDeal)
+ {
+ if (soundDamageOverTime != null && data.isPlaying && !data.dead)
+ {
+ SoundManager.Instance.Play(soundDamageOverTime, base.transform);
+ }
+ damageDealt += dpt;
+ health.DoDamage(damage.normalized * dpt, position, color, damagingWeapon, damagingPlayer, healthRemoval: true, lethal);
+ yield return new WaitForSeconds(interval / TimeHandler.timeScale);
+ }
+ }
+}