So so many people seem to be of the opinion that you never ever use anything static ever ever ever.
Then, sometimes, I see static methods being used within Unity tutorials.
I understand that classes that derive from Monobehaviour never have to be static:
public class MyClass : Monobehaviour {
int myInt;
}
public class MySecondClass : Monobehaviour {
MyClass myClass;
Start() {
myClass = this.gameObject.AddComponent<MyClass>();
myClass.myInt = 10;
}
}
…but when dealing with editor methods or methods in classes that don’t inherit from Monobehaviour, I have a tendency to want to create static methods so that I can access these utility methods:
public class xmlMethods {
public static void save(string filePath, Type objectType) {
//save xml code goes here
}
public static void load(string filePath, Type objectType) {
//load xml code goes here
}
}
There’s a tendency to want to do this, creating utility classes that I can use anywhere in my scripts, but it confuses me when people say to never ever use static methods ever. What’s the alternative?