Having wrapped up the game itself and making a main menu, I needed to have some visual feedback to let the player know when they press the “Start” button that the game is in fact loading. Enter the loading screen.
The visuals are simple enough, but linking the loading bar to the actual percentage of assets loaded is what makes it functional.
As mentioned briefly in my previous article, singletons are a pattern commonly used in programming both in and outside of Unity.
A Singleton is a class with only allows a single instance of itself to be created and accessed. These allow for you to call and store variables from various other sources and reference them from the script utilizing the Singleton pattern.
Singletons has many uses, but the utilization in my case is for my manager class objects (Game Manager, Audio Manager) due to the need to constantly access other scripts to get information. Instead of using GetComponent a dozen times, I can utilize this Singleton to store the information needed until it needs to be called.
Manager class objects are commonly used to manage different functions in gameplay. In this project, I used two; one controls the audio for the game and the other is used to end the introduction cutscene and allow the player control following the end of that cutscene.
These scripts follow a pattern known as a singleton (more on that in another article).
Manager classes can become a dumping pit of sorts, taking in variables and values that did not fit in other places and make them available to reference to a wide variety of other scripts.
This eliminates the need for GetComponent to be used in reference to the object the component is on over and over again!
In the previous article I covered the basics of navmeshing and baking the floor so the player could move across it by clicking on their desired location. There are some more minor edits that can be done to further improve this system.
First off, I replaced the placeholder capsule gameobject…