I am trying to create a function that runs on a set interval and updates a variable:
// Run this every set interval
void RepeatingFunction() {
someVariable++;
}
I was wondering if this would be an opportunity to use a co-routine and WaitForSeconds? The problem is, I'm unsure as to how to make the function repeat, I tried this:
void Start() {
StartCoroutine(RepeatingFunction());
}
private IEnumerator RepeatingFunction() {
yield return new WaitForSeconds(pathfindFrequency);
someVariable++;
RepeatingFunction();
}
But unfortunately it doesn't work. Could anyone suggest as to how I can achieve this? For the record, it is part of a pathfinding script, I want to repeat the function so I can get the closest node every set interval.