Am curious to know why even the Intermediate 2D RPG course would not use Events or Observer Pattern to update the Score UI ? Is it not favoured for performance reasons or for some other reason (debugging) ?
For example
public class PlayerHealth: Singleton<PlayerHealth>{
public event Action<int> PlayerHealthChangedEvent;
...
public void HealPlayer() {
if (_currentHealth < maxHealth) {
_currentHealth += 1;
HealthChangedEvent?.Invoke(_currentHealth);
}
}
}
public class UpdateUI:Monobehaviour{
...
private void Start(){
PlayerHealth.Instance.HealthChangedEvent += UpdateHealth;
}
private void UpdateHealth(int currentHealth){
healthSlider.value = currentHealth;
}
}
Are there any Unity Project based courses that teach the Observer design pattern or Events ?