Change the referenced variable from another class

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?

I had made some changes to your code as follows. The Cooldown coroutine will accept a Action as it parameter so that it can be used to set the bool value in other class.

using UnityEngine;
using System;
using System.Collections;

public static class HelperFunctions
{
	public static IEnumerator Cooldown(float duration, Action<bool> setCooldown)
	{
		setCooldown(true);

		float timer = 0f;
		while (timer < duration)
		{
			timer += Time.deltaTime;
			yield return null;
		}

		setCooldown(false);
	}
}

Here is an example of starting the coroutine:

public class Sheep : MonoBehaviour
{
	public bool cooldown = false;

	public void Start()
	{
		StartCoroutine(HelperFunctions.Cooldown(6, x => this.cooldown = x));
	}
}