How to create a loading scene in Unity

Restart scene

  • Create a UIManager script with a singleton
  • Import UnityEngine.SceneManagement
  • Create a method, for example, public void RestartGame()
  • In the method, call SceneManager.LoadScene(“… scene name …”). In this case, the scene’s name is Main1
  • Select the Restart button, Add a new OnClick event
  • Drag and drop UIManager gameobject into the bottom left slot
  • In the drop down list that says No Function, select UIManager/Restart()

Quit

  • Create a method, for instance, public void QuitGame()
  • In it, call Application.Quit()
  • Add the method to the button as described for the Restart button

Adding scenes to Build settings

  • Go to File/Build settings
  • Add the scenes manually (drag and drop) or click on Add Open Scenes

Loading bar

  • Create a new scene called LoadingScreen
  • Create 2 UI images: Background and Progress_bar
  • Add the images. Also you can add an overlay image
  • Set the image type to filled and Fill Method to Horizontal

Asynchronous operation

Implementation

  • Change the scene to load in MainMenu script to LoadingScreen
  • Add the scenes to the Build settings, preferably the first one at the top, in descending order (just a good practice)
private Image progressBarprivate void Start() => StartCoroutine(LoadProgressAsync());private IEnumerator LoadProgressAsync()
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(gameScene);

while (!asyncLoad.isDone) // while loading isn't finished
{
// progress bar fill amount = operation progress
progressBar.fillAmount = asyncLoad.progress;

yield return new WaitForEndOfFrame();
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store