|
|
|
|
|
|
|
|
|
|
private void OnEnable() |
|
|
|
{ |
|
|
|
_deathEvent.OnEventRaised += SetHealthBar; |
|
|
|
_updateHealthEvent.OnEventRaised += SetHeartImages; |
|
|
|
_deathEvent.OnEventRaised += RegisterDeath; |
|
|
|
_updateHealthEvent.OnEventRaised += UpdateHeartImages; |
|
|
|
_deathEvent.OnEventRaised += UpdateHeartImages; |
|
|
|
|
|
|
|
SetHealthBar(); |
|
|
|
} |
|
|
|
|
|
|
_updateHealthEvent.OnEventRaised -= SetHeartImages; |
|
|
|
_deathEvent.OnEventRaised -= SetHealthBar; |
|
|
|
_deathEvent.OnEventRaised -= RegisterDeath; |
|
|
|
} |
|
|
|
|
|
|
|
private void OnLevelWasLoaded(int level) |
|
|
|
{ |
|
|
|
SetHeartImages(); |
|
|
|
} |
|
|
|
|
|
|
|
public void SetHealthBar() |
|
|
|
{ |
|
|
|
_currentHealth.SetMaxHealth(_healthConfig.MaxHealth); |
|
|
|
_currentHealth.SetCurrentHealth(_healthConfig.MaxHealth); |
|
|
|
|
|
|
|
SetHeartImages(); |
|
|
|
} |
|
|
|
|
|
|
|
public void InflictDamage(int _damage) |
|
|
|
{ |
|
|
|
SetHeartImages(); |
|
|
|
_updateHealthEvent.OnEventRaised -= UpdateHeartImages; |
|
|
|
_deathEvent.OnEventRaised -= UpdateHeartImages; |
|
|
|
public void RestoreHealth(int _healthToAdd) |
|
|
|
private void SetHealthBar() |
|
|
|
SetHeartImages(); |
|
|
|
} |
|
|
|
_currentHealth.SetMaxHealth(_healthConfig.InitialHealth); |
|
|
|
_currentHealth.SetCurrentHealth(_healthConfig.InitialHealth); |
|
|
|
public void RegisterDeath() |
|
|
|
{ |
|
|
|
SetHealthBar(); |
|
|
|
UpdateHeartImages(); |
|
|
|
void SetHeartImages() |
|
|
|
private void UpdateHeartImages() |
|
|
|
{ |
|
|
|
int heartValue = _currentHealth.MaxHealth / _heartImages.Length; |
|
|
|
int filledHeartCount = Mathf.FloorToInt((float)_currentHealth.CurrentHealth / heartValue); |
|
|
|