Here’s my problem:
I want to use a normal variable within a static function.
Of course this doesn’t work unless the variable itself is static as well. My workaround so far has been to create a copy of that variable as a static variable, then assigning the normal variable to the static version in in Start or Update, and using the static version in my static function.
public float myNormalVar;
public static float MyStaticVar;
void Start() {
MyStaticVar = myNormalVar;
}
The other workaround I tried was turning my class into a singleton, and using a static property to return an instance of my normal variable:
public float myNormalVar;
public static float MyStaticVar { get{ return instance.myNormalVar; } }
But I don’t want to turn this class into a singleton, there’s never gonna be 2 instances of that class so using static variables works perfect for it.
I was wondering, am I doing this the right way or is there another way to use non-static variables within static functions?
Thanks for your help!
Stephane