Can you check a boolean in a coroutine?

I have one object checking for a coroutine in Update to return true, in which case it will detach itself from its parent.

But to me, it seems like a waste to be checking every single frame, as I don’t expect the boolean to change that frequently. Is it possible to check in a coroutine? Or would it even matter? Is this even a noticeable impact in overhead?

My specific script is pretty simple:

public EnemyDeath enemyDeath;

void Start () {

		enemyDeath = GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyDeath>();

}

void Update(){

		if(enemyDeath.enemyDead){

			transform.parent = null;
		}

Instead of constant checking you could use a delegate.

In the EnemyDeath script add:

public System.Action OnDeath;

And then in the same script, at the point where you set the enemyDead to true add:

If(OnDeath != null) // make sure something is assigned
{
   OnDeath();
}

Then in the script you shown in start:

 GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyDeath>().OnDeath += OnEnemyDeath;

And in the same script as a method:

private void OnEnemyDeath()
{
   transform.parent = null;
   GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyDeath>().OnDeath -= OnEnemyDeath;
}

This is a bit more typing, but gives you the knowledge about state change without constant checks, while still not forcing the EnemyDeath to know about other scripts.

One way to do this is properties.

private bool _enemyDead;
public bool enemyDead {
    get {
        return _enemyDead;
    }
    set {
        // Take action here
        _enemyDead = value;
    }
}