Tip of the Day: Loading Screen in Unity

Loading screens are an essential part of any video game, they help the player breathe before the next level is loaded and allows the game to load all the necessary assets of the next level.There is more than a way to do it, today we will explore creati…


This content originally appeared on Level Up Coding - Medium and was authored by Mohamed Hijazi

Loading screens are an essential part of any video game, they help the player breathe before the next level is loaded and allows the game to load all the necessary assets of the next level.

There is more than a way to do it, today we will explore creating a separate scene dedicated to the loading scene/screen. This way, you will have way more control during the loading process. For example, you can add animations, tips, and much more.

Loading Screen Scene

So create a new scene, “Loading Scene”, and then create your loading UI. Add any elements or assets you want to load during this scene.

Here is an example sample scene.

As in most loading scenes, we added a progress bar that will tell us how far is the loading progress is. We did this by creating an image and changing the image type to “Filled” and fill method to Horizontal, this way we can control the fill amount.

So far so good, easy right? Not quite.

A. How will we control the loading system?

First off, to make all this possible we need to use an AsyncOperation. This operation is like a simple SceneManager.LoadScene but will allow the scene to load the assets before actually loading the next scene.

B. The major problem now is how do we tell the loading scene which scene to load?

We need a method that will allow the transfer of variables between two different scenes, this is why we will use a costume STATIC class that has one propose: telling the load scene which scene to load next.

Here is how to do it:

A. Create a C# script and make it a custom class (Remove Monobeahaviour, start and update). This will hold a global static string that will tell which next scene to load.

C. Finally in your level, create a C# script that will act as a trigger to load the “Loading Scene”, in this script you will have a public string of the next level you want to load and assign it to the global string we created in the custom LoadingData script.

So how will all this method come together?

From the main menu or any level, you use the LoadingSceneTrigger script to quickly load up the Loading Screen Scene and assign the global string sceneToLoad in order to be used in the loading screen scene. Here the scene will automatically start the Async Operation to load the next. ‘

This method will allow you to use one Loading Scene and save you time in the long run.

And there you have it, a simple and efficient modular loading system.


Tip of the Day: Loading Screen in Unity was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Mohamed Hijazi


Print Share Comment Cite Upload Translate Updates
APA

Mohamed Hijazi | Sciencx (2021-04-24T00:18:57+00:00) Tip of the Day: Loading Screen in Unity. Retrieved from https://www.scien.cx/2021/04/24/tip-of-the-day-loading-screen-in-unity/

MLA
" » Tip of the Day: Loading Screen in Unity." Mohamed Hijazi | Sciencx - Saturday April 24, 2021, https://www.scien.cx/2021/04/24/tip-of-the-day-loading-screen-in-unity/
HARVARD
Mohamed Hijazi | Sciencx Saturday April 24, 2021 » Tip of the Day: Loading Screen in Unity., viewed ,<https://www.scien.cx/2021/04/24/tip-of-the-day-loading-screen-in-unity/>
VANCOUVER
Mohamed Hijazi | Sciencx - » Tip of the Day: Loading Screen in Unity. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/24/tip-of-the-day-loading-screen-in-unity/
CHICAGO
" » Tip of the Day: Loading Screen in Unity." Mohamed Hijazi | Sciencx - Accessed . https://www.scien.cx/2021/04/24/tip-of-the-day-loading-screen-in-unity/
IEEE
" » Tip of the Day: Loading Screen in Unity." Mohamed Hijazi | Sciencx [Online]. Available: https://www.scien.cx/2021/04/24/tip-of-the-day-loading-screen-in-unity/. [Accessed: ]
rf:citation
» Tip of the Day: Loading Screen in Unity | Mohamed Hijazi | Sciencx | https://www.scien.cx/2021/04/24/tip-of-the-day-loading-screen-in-unity/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.