summaryrefslogtreecommitdiff
path: root/GameCode/LightManager.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-21 10:28:46 +0800
committerchai <215380520@qq.com>2024-03-21 10:28:46 +0800
commit3fb2121cc0d00cbd42b2ca10b5dfb399a4df1a04 (patch)
treec1f4683fb021522b459408ab1ad61c40be77ee47 /GameCode/LightManager.cs
parent9ee2cfa385ed77c39003f524f5f03079124fc476 (diff)
*misc
Diffstat (limited to 'GameCode/LightManager.cs')
-rw-r--r--GameCode/LightManager.cs62
1 files changed, 62 insertions, 0 deletions
diff --git a/GameCode/LightManager.cs b/GameCode/LightManager.cs
new file mode 100644
index 0000000..e38ac0f
--- /dev/null
+++ b/GameCode/LightManager.cs
@@ -0,0 +1,62 @@
+using System.Collections;
+using UnityEngine;
+
+public class LightManager : MonoBehaviour
+{
+ [SerializeField]
+ private Color stage2Color;
+
+ [SerializeField]
+ private Color stage3Color;
+
+ [SerializeField]
+ private Color stage4Color;
+
+ [SerializeField]
+ private Light light;
+
+ private void Start()
+ {
+ }
+
+ public void ChangeColor(int stage)
+ {
+ switch (stage)
+ {
+ case 2:
+ StartCoroutine(ShiftLight(stage2Color, 180f));
+ break;
+ case 3:
+ StartCoroutine(ShiftLight(stage3Color, 180f));
+ break;
+ case 4:
+ StartCoroutine(ShiftLight(stage4Color, 180f));
+ break;
+ }
+ }
+
+ private IEnumerator ShiftLight(Color newColor, float rotationInDeg)
+ {
+ Color startColor = light.color;
+ Vector3 startEuler = light.transform.eulerAngles;
+ Vector3 newEuler = startEuler + new Vector3(0f, rotationInDeg, 0f);
+ float timer = 0f;
+ float count = 0f;
+ while (timer < 1f)
+ {
+ light.color = Color.Lerp(startColor, newColor, timer);
+ light.transform.eulerAngles = Vector3.Lerp(startEuler, newEuler, timer);
+ count += Time.deltaTime;
+ if (count > 60f)
+ {
+ Debug.LogError("Possible infinite loop");
+ break;
+ }
+ timer += Time.deltaTime / 30f;
+ yield return new WaitForEndOfFrame();
+ }
+ light.color = newColor;
+ light.transform.eulerAngles = newEuler;
+ yield return null;
+ }
+}