Utility Class
Last updated
Last updated
We will create a static class: Utility
that has static methods we can call from any script without creating an object instance of the class.
We have been using static methods of the GameObject class, such as: GameObject.Find( ). Static methods provide a convenient way to create methods that we'll use across a series of classes, for functionality that is not specific to a single class. A perfect example of this type of method is that we often want to toggle visibility of a UI-Panel, and we can do this by adding a Canvas Group component to the UI gameObject.
Notice, the class is marked as static and each method is also marked as public static. This means we can use the method in another class with the following syntax:
To control visibility of UI Elements, add a CanvasGroup component. The CanvasGroup provides control of the alpha transparency, and interactivity, and Blocks Raycasts for UI elements.
Since this is functionality that we'll use frequently, we'll
write the code as a public static
method in a custom Utility class that can be executed from within any other script.