wirm/Game/Assets/Scripts/SceneTransition.cs

32 lines
849 B
C#
Raw Permalink Normal View History

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