How To Create A Loading Scene In Unity
A “Loading Scene” is just a simplified scene that you have visible while you “Asynchronously” load the next scene in the background. This allows the scene with your game to fully render what is needed before allowing the player to see it.
The first step to creating your loading scene is to “Create A New Scene”.
This scene should consist of something simple such as a background image and a loading bar. So let’s delve into it!
Once you’ve added an image to your scene, Unity will automatically create a ”Canvas” for it to sit on.
In order to keep everything working as intended no matter who accesses your game, you’ll want to access the “Canvas Scaler” component within your “Canvas” game object.
Change the “UI Scale Mode” to “Scale With Screen Size”.
Set the “Reference Resolution” parameter to whatever your base game resolution is.
And change the “Match” parameter to set the resolution scale equally in both width and height by centering it at (.5).
Next, you’ll want to add a loading bar that will fill as the next scene loads
Start by adding a new image and stretching it across your screen as you see fit. This image will be the progress bar so keep that in mind.
Change your progress bar’s “Image Type” to “Filled”.
Change the “Fill Method” top “Horizontal”.
And set the “Fill Origin” to “Left”.
You can use similar methods to this but using the other “Fill Methods” such as radial to create interesting effects for things like cooldowns.
Notice how the “Fill Amount” now controls your loading bar based on its value! This is what we will be accessing and adjusting in order to provide an effect that visually displays the load’s progress.
If you want your game to look pretty, layering on images can help the images that you want to stand out have more oomph. In this case, creating a layer to go behind the loading bar will make it look cleaner AND show the player a visual marker as to where the loading bar needs to get to in order to finish.
Next, create a new C# script and add it to your canvas.
You will need to add the “Namespaces” (using UnityEngine.UI) as well as (using UnityEngine.SceneManagement). These will give you access to using operations and properties that we need such as those seen in “bright yellow” in the example below.
Don’t forget to include your frame delay (yield return new WaitForEndOfFrame) when testing a while loop. If you’re not careful it will run infinitely and crash your computer! If you’re using Windows and this happens, press “Ctrl+Alt+Delete” on your keyboard to access your “Task Manager” and shut Unity down immediately. If that fails, hard shutdown your computer by holding down the power button as you run the risk of frying components within your pc.
Next, you will need to drag your “Progress Bar” game object into the script reference that you just made for it. And lastly, you will need to enter your build settings and add the scenes that you are working with.
And that’s it! You should see your game run perfectly fine if you test it out, and load your next scene while your loading screen appears AND animates “Asynchronously” with your level!
Once your scene is fully loaded using the script we created previously, Unity will immediately transition you over to the next scene without any more work!
That’s the end of my development on this project! “The Great Fleece” is complete! Check the game out on my “Git Hub”!
Contribute to adamwreed93/3D_Stealth_Game development by creating an account on GitHub.
And I’ll see you all next time!