private void OnPlayerChanged(string playerName) { if (!activePlayer.text.Equals(playerName)) { var activePlayerBefore = activePlayer.text; var lastPlayerfontStyle = activePlayer.fontStyle; FontStyles inactivePlayerfontStyle; if (inactivePlayerLeft.text.Equals(playerName)) { inactivePlayerfontStyle = inactivePlayerLeft.fontStyle; inactivePlayerLeft.text = activePlayerBefore; inactivePlayerLeft.fontStyle = lastPlayerfontStyle; } else { inactivePlayerfontStyle = inactivePlayerRight.fontStyle; inactivePlayerRight.text = activePlayerBefore; inactivePlayerRight.fontStyle = lastPlayerfontStyle; } activePlayer.text = playerName; activePlayer.fontStyle = inactivePlayerfontStyle; foreach (var healthSo in healthSOs) { if (healthSo.name.Equals(playerName)) { this.healthSO = healthSo; break; } } } }
private void Awake() { if (_currentHealthSO == null) { _currentHealthSO = new HealthSO(); _currentHealthSO.SetMaxHealth(_healthConfigSO.MaxHealth); _currentHealthSO.SetCurrentHealth(_healthConfigSO.MaxHealth); } if (_updateHealthEvent != null) { _updateHealthEvent.RaiseEvent(); } }
private void Start() { gameManager.ShouldRestartGame += OnShouldRestartGame; playerManager.PlayerChanged += OnPlayerChanged; playerManager.PlayerDied += OnPlayerDied; foreach (var healthSo in healthSOs) { if (healthSo.name.Equals("Jumper")) { this.healthSO = healthSo; break; } } }
private void Awake() { //If the HealthSO hasn't been provided in the Inspector (as it's the case for the player), //we create a new SO unique to this instance of the component. This is typical for enemies. if (_currentHealthSO == null) { _currentHealthSO = ScriptableObject.CreateInstance <HealthSO>(); _currentHealthSO.SetMaxHealth(_healthConfigSO.InitialHealth); _currentHealthSO.SetCurrentHealth(_healthConfigSO.InitialHealth); } if (_updateHealthUI != null) { _updateHealthUI.RaiseEvent(); } }