summaryrefslogtreecommitdiff
path: root/GameCode/LineEffectExplosionModifier.cs
blob: 3f1c66ba3366e4a73ebc37c75fa58af6d6223510 (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
using System;
using System.Collections;
using UnityEngine;

public class LineEffectExplosionModifier : MonoBehaviour
{
	public AnimationCurve curve;

	public float speed = 1f;

	private LineEffect effect;

	private Coroutine corutine;

	private void Start()
	{
		effect = GetComponent<LineEffect>();
		Explosion componentInParent = GetComponentInParent<Explosion>();
		componentInParent.DealDamageAction = (Action<Damagable>)Delegate.Combine(componentInParent.DealDamageAction, new Action<Damagable>(DealDamage));
		Explosion componentInParent2 = GetComponentInParent<Explosion>();
		componentInParent2.DealHealAction = (Action<Damagable>)Delegate.Combine(componentInParent2.DealHealAction, new Action<Damagable>(DealDamage));
	}

	public void DealDamage(Damagable damagable)
	{
		if (corutine != null)
		{
			StopCoroutine(corutine);
		}
		corutine = StartCoroutine(DoCurve());
	}

	private IEnumerator DoCurve()
	{
		float c = 0f;
		float t = curve.keys[curve.keys.Length - 1].time;
		while (c < t)
		{
			effect.offsetMultiplier = curve.Evaluate(c);
			c += TimeHandler.deltaTime * speed;
			yield return null;
		}
	}
}