Static Types Pt. 2- C# Skill in Unity: 3
Objective: using static type to create utility helper class.
Static type can also be very helpful by using it to create a utility helper. As static type can be called from any class, it can hold some methods to be called during the game.
Let’s create a helper that would readjust the position of a gameobject.
Create a new script and set this script as a static class.
Then create a method with passing in a gameobject, and readjust the position of this gameobject to a fixed position.
As this method, you can imagine that sometimes you might need to set something back to a fixed position during the game and you have not set the reference, or it can be a reset system when you want to readjust it.
Now our method is ready, let’s call it from another script.
Using utility helper
Create another script and assign it to an object in game.
Then we can call the ReadjustPosition() method in Player script.
Now we can test it in the Play mode.
As you can see it is so easy to call a method from a static class.
And that is how to create a utility helper by using static class.