I have a strange behavior occurring in my game, the first load from another scene is less than a second, but if the player dies, it trigger a SceneManager.LoadScene(“same scene”), and now the loading takes like 5 minutes, here an Image to illustrate:
I tried to load another scene that loads the main game again, but it just didn’t work:
Here is the trigger of the game over:
IEnumerator Death()
{
float ElapsedTime = 0;
while (Time.timeScale > 0)
{
ElapsedTime += Time.fixedDeltaTime/5;
Time.timeScale = Mathf.Clamp01(1f - ElapsedTime);
if (Custom)
{
GameObject.Find("Difficulty_Script").GetComponent<AudioSource>().volume = Mathf.Clamp01(1f - ElapsedTime);
}
else
{
Music.volume = Mathf.Clamp01(1f - ElapsedTime);
}
HUD.alpha = Mathf.Clamp01(1f - (ElapsedTime * 2));
Blur.SetFloat("_Size", ElapsedTime * 2);
yield return null;
}
ElapsedTime = 0;
while (ElapsedTime < 1)
{
ElapsedTime += Time.fixedDeltaTime/5;
GameOver.color = new Color(1,1,1, Mathf.Clamp01(0f + ElapsedTime));
yield return null;
}
ElapsedTime = 0;
while (ElapsedTime < 1)
{
ElapsedTime += Time.fixedDeltaTime /5;
Fade.color = new Color(0, 0, 0, Mathf.Clamp01(0f + ElapsedTime));
yield return null;
}
Time.timeScale = 1;
SceneManager.LoadScene("Reloading");
yield return null;
}
(Ignore all the Mathf, I’ll change it later :P)