GameDevHQ Crash Course #25 Static Managers
Sometimes you don’t want an object to be destroyed and recreated every time a scene is loaded, like something controlling your settings, your inventory ect.
So for these manager type scripts we create a static version of them, they don’t change throughout the game get given data to hold and to send, this also opens up the ability to reference these scripts easier as we know they will be loaded.
First thing we make it with a static variable or a static method or even make the entire class static, this will then force the script to be static, then we need to make sure it load immediately and is accessible by other scripts by putting it in to a private static class and using the awake class, the awake class gets called before start classes, so if things needed to be for sure loaded before others, awake is where you want to put them, we have a public static method to return the class as we don’t want anything messing with the static variable, then you can call this class from any other script by in this instance using UIManager.Instance.METHOD instead of having to find the script component from a different object, because we know it will always be loaded.
Manager classes are in generally really important and something that should be static as you want to be sure they are loaded once and only once to do various critical functions, like level loading, player movement, player stats and so on.