I'm using this code to fade in a CanvasGroup at the beginning of my scene loading, and then if the player loses I want to fade out the scene and reload it from the beginning.
void Update () {
if (Time.time < 1 && fade.alpha >= 0)
fade.alpha = .99f - Time.time;
if (fadeOut)
fade.alpha += .02f;
if (fade.alpha >= 1)
{
Debug.Log("Change scene");
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
The problem is that when it hits this it shows the gamescene twice in the hierarchy, and neither one on the screen. I'll upload a picture below. When it does this is also hits the Debug.Log repeatedly.
Does this not work if it's the only scene in the project? Only thing I can think of.
I've updated the method to include a boolean to ensure it SHOULD only run one time. Somehow it is still running countless times until I end the unity editor. The new update method is this :
void Update () {
if (Time.time < 1 && fade.alpha >= 0)
fade.alpha = .99f - Time.time;
if (fadeOut)
fade.alpha += .02f;
if (fade.alpha >= 1 && !reloadStarted)
{
Debug.Log("Change scene");
reloadStarted = true;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}