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().OnDeath += OnEnemyDeath;
And in the same script as a method:
private void OnEnemyDeath()
{
transform.parent = null;
GameObject.FindGameObjectWithTag("Enemy").GetComponent().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.
↧