game(scripts): standardise SceneTransition

This commit is contained in:
Mark Joshwel 2025-02-15 00:36:21 +08:00
parent 9c945c535d
commit c6d0f73340

View file

@ -1,10 +1,10 @@
using System.Collections; using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
// NOTE: / FIXME: no asset usages, and school is not a tag; is this script dead?
public class SceneTransition : MonoBehaviour public class SceneTransition : MonoBehaviour
{ {
public Image fadeImage; // Assign the black image here public Image fadeImage; // Assign the black image here
@ -12,20 +12,17 @@ public class SceneTransition : MonoBehaviour
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
if (other.CompareTag("School")) if (other.CompareTag("School")) StartCoroutine(FadeOutAndLoadScene());
{
StartCoroutine(FadeOutAndLoadScene());
}
} }
private IEnumerator FadeOutAndLoadScene() private IEnumerator FadeOutAndLoadScene()
{ {
float elapsed = 0f; var elapsed = 0f;
while (elapsed < fadeDuration) while (elapsed < fadeDuration)
{ {
elapsed += Time.deltaTime; elapsed += Time.deltaTime;
float alpha = Mathf.Clamp01(elapsed / fadeDuration); var alpha = Mathf.Clamp01(elapsed / fadeDuration);
fadeImage.color = new Color(0, 0, 0, alpha); fadeImage.color = new Color(0, 0, 0, alpha);
yield return null; yield return null;
} }