So, I’ve got what I thought would be a simple problem. I have a function that takes a variable, a value, and a delay, and adds the value to the variable, after delay seconds. It has to be an IEnumerator to I can have the delay.
But how do I pass the variable to the function?
void Start ()
{
delayedStatisticUpdate (health, 5, -1);
delayedStatisticUpdate (hunger, 50, 10);
delayedStatisticUpdate (energy, 1, -10);
delayedStatisticUpdate (level, 10, 1);
}
public static IEnumerator delayedStatisticUpdate (int *statistic, int delay, int change)
{
yield return new WaitForSeconds(delay);
*statistic += change;
Debug.Log("delayedUpdate happened");
}
Obviously my start and update functions are far more complex, and called delayedStatistcUpdate is being called from multiple scripts, but thats not the issue here.
I’m getting 2 errors:
error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
and
error CS1637: Iterators cannot have unsafe parameters or yield types
Could anyone tell me how I SHOULD be doing this?