Quantcast
Channel: Answers by "AyAMrau"
Viewing all articles
Browse latest Browse all 91

Answer by AyAMrau

$
0
0
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.

Viewing all articles
Browse latest Browse all 91

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>