game(scripts): standardise SceneTransition
This commit is contained in:
parent
9c945c535d
commit
c6d0f73340
1 changed files with 6 additions and 9 deletions
|
@ -1,10 +1,10 @@
|
|||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// NOTE: / FIXME: no asset usages, and school is not a tag; is this script dead?
|
||||
|
||||
public class SceneTransition : MonoBehaviour
|
||||
{
|
||||
public Image fadeImage; // Assign the black image here
|
||||
|
@ -12,24 +12,21 @@ public class SceneTransition : MonoBehaviour
|
|||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("School"))
|
||||
{
|
||||
StartCoroutine(FadeOutAndLoadScene());
|
||||
}
|
||||
if (other.CompareTag("School")) StartCoroutine(FadeOutAndLoadScene());
|
||||
}
|
||||
|
||||
private IEnumerator FadeOutAndLoadScene()
|
||||
{
|
||||
float elapsed = 0f;
|
||||
var elapsed = 0f;
|
||||
|
||||
while (elapsed < fadeDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
float alpha = Mathf.Clamp01(elapsed / fadeDuration);
|
||||
var alpha = Mathf.Clamp01(elapsed / fadeDuration);
|
||||
fadeImage.color = new Color(0, 0, 0, alpha);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
SceneManager.LoadScene("NextScene");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue