summaryrefslogtreecommitdiff
path: root/GameCode/MenuEffects.cs
blob: 534598449db45869580af3d4913f1f8eda9e0135 (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
using System.Collections;
using TMPro;
using UnityEngine;

public class MenuEffects : MonoBehaviour
{
	public static MenuEffects instance;

	public Color nopeColor;

	private void Awake()
	{
		instance = this;
	}

	public void ShakeObject(GameObject objectToShake, Vector3 defaultPos, float amount, float time)
	{
		StartCoroutine(DoShakeObject(objectToShake, defaultPos, amount, time));
	}

	private IEnumerator DoShakeObject(GameObject objectToShake, Vector3 defaultPos, float amount, float time)
	{
		float c = 0f;
		while (c < time)
		{
			Vector3 localPosition = defaultPos + Random.onUnitSphere * amount * ((time - c) / time);
			localPosition.z = defaultPos.z;
			objectToShake.transform.localPosition = localPosition;
			c += Time.unscaledDeltaTime;
			yield return null;
		}
		objectToShake.transform.localPosition = defaultPos;
	}

	public void BlinkInColor(TextMeshProUGUI textToBlink, Color blinkColor, Color defaultColor, float seconds)
	{
		StartCoroutine(DoTextColorBlink(textToBlink, blinkColor, defaultColor, seconds));
	}

	private IEnumerator DoTextColorBlink(TextMeshProUGUI textToBlink, Color blinkColor, Color defaultColor, float seconds)
	{
		float c = 0f;
		while (c < seconds)
		{
			textToBlink.color = blinkColor;
			c += Time.unscaledDeltaTime;
			yield return null;
		}
		textToBlink.color = defaultColor;
	}
}