Day 83: How to Create A Loading Scene in Unity

Objective: Create a loading scene to load the game.

To start off on this adventure of loading a scene in Unity, we will need to create a new scene, let’s name it LoadingScene.

In this scene we will need to create three image objects, One to hold the background image, one to hold the progress bar and finally one to hold the overlay that covers the progress bar.

After we add in the correct images to it’s location, we’ll go to the progress bar. In the Image component, we need to set the image type to Filled. Filled method to horizontal and origin to left. This will allow us to fill the image to match the amount of progress that has been made.

Once this is all set it, it’s time to get into the logic. We will create a LoadLevel script and attach it to the canvas object.

Now that we are in the script, we need to create an variable to hold the progress bar object. But to use UI variables we need to add the library first. Since this will load the main game, we might as well add SceneManagement as well now.

We need a variable to hold the Image object for the progress bar.

Now we are gonna create an IEnumerator that’ll hand the loading of the next scene. We will need to create a AsyncOperation and assign it the SceneManager.LoadSceneAsync(“Pass in the scene name you want to load”);. Next we will need to use a while loop to run while the asyncLoad is not done loading. Inside the while loop, we will use the image object and set the fillamount to equal the asyncLoad.progress. We do need to let the program breath so we will yield return new WaitForEndOfFrame();

In the start function we need to start the CoRoutine.

All that’s left to do is in the main menu change the loadscene to loadLevel and not the main game scene.

This is our MainMenu script.

To learn more about AsyncOperation head off to here and learn a little bit more.

Thank you for reading and have a wonderful day!




I am passonate on learning to program and use Unity to become a skillful Unity Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What a junior developer needs from a team

What are the top 5 reasons to choose Ruby on Rails to develop application for your startup?

【May 2022】 RTX3060(LHR) Mining Optimization Settings *LHR completely removed

High-Definition Rendering Pipeline in Unity

Virtual Reality and Progressive Web Apps

5 Steps to Master Python Decorator

PyQGIS — Script for visualization of grid-based data

How to prepare your Linux/MacOS box for Ionic 3 development

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
Tyler Smallwood

Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer

More from Medium

Loading Scenes In Unity

Adding a Main Menu to our UI

Day 101: Character Animation Part 4

Unity Interface Layout