call InvokeRepeating from a static method (C#)

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.

You need a MonoBehaviour instance to attach the invoke instruction to it. E.g.

public class TestScript : MonoBehaviour {

    public static TestScript instance;

    void Awake () {
         instance = this;
    }

    public static void startThisFunction () {
        if (instance)
            instance.InvokeRepeating("doThisFunction", 0.1f, 5.0f);
    }

    void doThisFunction() {
        Debug.Log("Just a simple test");
    }
}

This is a dirty draft to try to explain how things work. Better check the singleton design pattern.