I am trying to optimize my code by "globalizing" functions that do the same thing. However, I've run into a snag that I don't fully understand and I'd like some help in solving it.
Take this very basic script:
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour {
public void startThisFunction() {
InvokeRepeating("doThisFunction", 0.1f, 5.0f);
}
void doThisFunction() {
Debug.Log("Just a simple test");
}
public static void startThisFunctionAsStatic() {
startThisFunction();
}
}
It doesn't do anything, it's just for me to try and understand how to do this.
If I change "startThisFunction" to a static method, I get an error stating InvokeRepeating requires a reference to it. However, as we all know, you can't reference MonoBehaviour by a "new" call, so how do I do it?
I tried adding a calling method "startThisFunctionAsStatic" but this obviously doesn't work so how can I call a non-static MonoBehaviour method from within a static method?
I hope I've explained clear enough what I'm after and any help will be greatly appreciated.
Trending Articles
More Pages to Explore .....