I have the following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class SceneFader : MonoBehaviour {
public Image img;
public AnimationCurve curve;
private float _progress = 0f;
public Text loadingText;
private void Start()
{
StartCoroutine(FadeIn());
}
public void FadeTo(string scene)
{
StartCoroutine(FadeOut(scene));
}
IEnumerator FadeIn()
{
float t = 1f;
while(t > 0f)
{
t -= Time.deltaTime;
float a = curve.Evaluate(t);
img.color = new Color(0f, 0f, 0f, a);
yield return 0;
}
}
IEnumerator FadeOut(string scene)
{
AsyncOperation operation = SceneManager.LoadSceneAsync(scene);
operation.allowSceneActivation = false;
while(_progress < 1f)
{
_progress = Mathf.Clamp01(operation.progress / 0.9f);
loadingText.text = "Loading... " + (int)(_progress * 100f) + "%";
//Debug.Log("Loading... " + (int)(_progress * 100f) + "%");
yield return null;
}
float t = 0f;
while (t < 1f)
{
t += Time.deltaTime;
float a = curve.Evaluate(t);
img.color = new Color(0f, 0f, 0f, a);
loadingText.color = new Color(1f, 1f, 1f, a);
yield return 0;
}
//SceneManager.LoadScene(scene);
operation.allowSceneActivation = true;
}
}
and as the title say, the loadingText don’t update to show what is in the function