Creating the UI controller
It will be convenient to have a script with a small API that makes it easy to switch between UI panels. For the controller scripts in our framework, I've decided to define them as singletons.
A singleton is a software design pattern that ensures there is only a single instance of a script object at runtime. Then, the object's instance can be more easily referenced, using a static reference to Instance in the class definition. Learn more at https://wiki.unity3d.com/index.php/Singleton.
Then, we'll write a UIController script that controls the visibility of your UI panels. Lastly, we'll implement some code to fade in and out for a more pleasing user experience when we hide and show the panels.
Creating a Singleton class script
We'll begin by writing a Singleton class to use (or, if you already have a favorite, feel free to use that Singleton class definition instead). You can find some singleton implementations available...