From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/MenuEffects.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 GameCode/MenuEffects.cs (limited to 'GameCode/MenuEffects.cs') 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; + } +} -- cgit v1.1-26-g67d0