I have like 10 classes performing 10 functions that are almost the same. The function is a cooldown, which looks something like this:
StartCoroutine(Cooldown());
IEnumerator Cooldown()
{
this.cooldown = true;
float timer = 0f;
while (timer < 6f)
{
timer += Time.deltaTime;
yield return null;
}
this.cooldown = false;
}
But now I wish to have this IEnumerator in a “helper” class, instead of repeating this code in 10 different classes.
So what I want is something like this:
public class Sheep {
public bool cooldown = false;
StartCoroutine(Cooldown());
}
public class HelperFunctions {
IEnumerator Cooldown(float duration, bool cooldown)
{
cooldown = true;
float timer = 0f;
while (timer < 6f)
{
timer += Time.deltaTime;
yield return null;
}
cooldown = false;
}
}
But I don’t want to change the bool inside the Cooldown() function. I want to change the “REAL” cooldown variable in Sheep class, without calling sheep.cooldown = false/true. How can I do this? Will I have to use Pointers?