Hi, I am trying to make a starting menu for my game where you will have the start button and the exit button. If you press the start button it would change the menu scene to game scene, and also it will show you loading bar of the scene loading. But I have this problem, if I click on the start button nothing happens and unity just stops working. I can not click anything or close the unity itself. Here is the code
public void ChangeScene()
{
LoadNextLevel();
}
void LoadNextLevel()
{
menu.SetActive(false);
loadingScreen.SetActive(true);
AsyncOperation operation = SceneManager.LoadSceneAsync(1);
while (!operation.isDone)
{
loadingBar.fillAmount = Mathf.Clamp01(operation.progress / 0.9f);
}
}
You are blocking the render thread with your while loop.
1 Like
Sorry my bad. I was googling the whole time and found out that I cannot use AsyncOperation in a method. I was following a tutorial and I missed that the guy created a coroutine not method like I did. Thanks for reply. Also can I make the loading like last longer? Now the loading screen pop up just for 1 second or less and the second scene is loaded. Like some timer or something like that. Thanks again.
WHy would you like it to last longer than the scene? But sure you can have a min loading time constant subtract the actual time it took and then yield return waitseconds if its larger than 0
Thanks. I am gonna try it. I need it because now as i stated in the previous comment, it loads like super fast so the loading screen is just useless. I will add some 3d models when i’ll complete those basic functions. But I don’t think that It would take that much longer to load to that point that the loading screen would be usefull.
I would instead defer the loading screen, If loading takes less than 0,4 seconds do not show the loading progress bar at all.
See, I didn’t think of this. Excellent idea
1 Like