- Home /
Question by
valengguerra · Jun 20, 2019 at 10:16 PM ·
androidloadingstuckloading screen
Loading screen gets stuck sometimes
I have a loading screen that is just a panel that contains an image and a loading bar, it displays over the actual scene and when the load is done, it changes to the other scene. Sometimes, the panel appears correctly but the loading bar gets stuck in 0% idk why. Here is the code from the loading script:
public void LoadNextScene(int index)
{
Time.timeScale = 1;
StartCoroutine(LoadAsync(index));
}
IEnumerator LoadAsync(int index)
{
yield return new WaitForSeconds(0.5f);
AsyncOperation operation = SceneManager.LoadSceneAsync(index);
while (!operation.isDone)
{
float progress = Mathf.Clamp01(operation.progress / 0.9f);
if (progress2 < 1f) {
progress2 = progress2 + 0.18f + Random.Range(0.02f, 0.08f); // its kinda fake progress
if (progress2 > 1f){ progress2 = 1f; } // because it used to load so fast and then take a while around 80-90% until finishing
}
else { progress = 1f; }
porcentaje.text = Mathf.Round(progress2 * 100f) + "%";
barra.value = progress2;
yield return null;
}
Comment