diff options
Diffstat (limited to 'GameCode/MenuEffects.cs')
-rw-r--r-- | GameCode/MenuEffects.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/GameCode/MenuEffects.cs b/GameCode/MenuEffects.cs new file mode 100644 index 0000000..5345984 --- /dev/null +++ b/GameCode/MenuEffects.cs @@ -0,0 +1,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; + } +} |