Hi Waleed,
Usually, we need a reference to access a method or a field inside an instance of a class. In this case, we would use GetComponent<T>()
or another method to find the reference to the desired instance.
However, if, for example, a method is not meant to be part of a specific instance but meant to be more general, we can use the static
keyword. It allows us to access the method directly via the class name and the dot notation.
When you read our PlayerPrefsController class, you’ll notice that we access the PlayerPrefs in the same way: PlayerPrefs.SetInt(...)
. This indicates that the static keyword is involved. It also means that you cannot use multiple PlayerPrefs instances because you cannot create any. The same applies to our PlayerPrefsController. And Mathf, which you used in other projects, e.g. Mathf.Clamp
.