How to make a loading scene with canvas and slider

Hi all,

im trying to make a loading scene, actually when the player click on play button on main menu screen, im showing a panel with a slider and want this slider behave like a progress bar. anyone has a simple tutorial or code to make this? thanks

You’ll have to use LoadLevelAsync to load it. LoadLevelAsync returns an AsyncOperation, which will have a progress variable you can keep an eye on over the next few seconds as it loads, and set your slider’s percentage to.

It’d probably look like this:

private AsyncOperation loadingOp = null;
public void OnButtonPressed() {
loadingOp = Application.LoadLevelAsync("YourLevel");
}

public Slider slider;
void Update() {
if (loadingOp != null) {
slider.gameObject.SetActive(true);
slider.value = loadingOp.progress;
}
else {
slider.gameObject.SetActive(false);
}
}

One important note is that this won’t appear to work when playing in the Editor. It’s only in the build that your assets will be compiled such that asynchronous loading can happen; in the Editor LoadLevelAsync just behaves like LoadLevel.

1 Like

awsome! thanks so much! ill try that