summaryrefslogtreecommitdiff
path: root/GameCode/RemoveAfterSeconds.cs
blob: 8232562870cce22fe8263f06792274093ec286c4 (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
using UnityEngine;

public class RemoveAfterSeconds : MonoBehaviour
{
	public float seconds = 3f;

	private float startSeconds;

	public bool shrink;

	public bool scaleWithScale;

	private float shrinkSpeed = 1f;

	private Vector3 startScale;

	private AnimationCurve curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);

	private float counter;

	private void Start()
	{
		startSeconds = seconds;
		startScale = base.transform.localScale;
		shrinkSpeed = Random.Range(1.5f, 2.5f);
	}

	private void Update()
	{
		seconds -= TimeHandler.deltaTime * (scaleWithScale ? (1f / base.transform.localScale.x) : 1f);
		if (!(seconds < 0f))
		{
			return;
		}
		if (shrink)
		{
			counter += Time.deltaTime * shrinkSpeed;
			base.transform.localScale = Vector3.Lerp(startScale, Vector3.zero, curve.Evaluate(counter));
			if (counter > 1f)
			{
				Object.Destroy(base.gameObject);
			}
		}
		else
		{
			Object.Destroy(base.gameObject);
		}
	}

	public void ResetCounter()
	{
		seconds = startSeconds;
	}
}