private void UpdateHealthBar(CurrentPlayerHealth health) { // TODO: Get max health of player float maxHealth = 100f; float healthPercentage01 = Mathf.Clamp01((float)health.Health / maxHealth); UpdateHealthBarPercentage01(healthPercentage01); }
public void ShowCurrentHealth(CurrentPlayerHealth health) { _healthBar.GetControl.value = health.CurrentHealth; if (health.CurrentHealth <= 0) { _uiGameScene.GameOver(); } }
private void OnCollisionEnter(Collision target) { _playerHealth = target.gameObject.GetComponent <CurrentPlayerHealth>(); if (_playerHealth) { _playerHealth.ApplyDamage(_damage); ShowExplosion(); DestroyObstacle(); } _bullet = target.gameObject.GetComponent <Bullet>(); if (_bullet) { _bullet.gameObject.SetActive(false); ShowExplosion(); DestroyObstacle(); } }
private void Start() { var core = GetComponent <PlayerCore>(); CurrentPlayerHealth.Value = playerMaxHealth; ReceiveDamageObservable.Do(_ => canSufferDamage = false) .Delay(TimeSpan.FromSeconds(InvincibleTime)) .Subscribe(_ => canSufferDamage = true); //this.UpdateAsObservable() //.Subscribe(_ => Debug.Log(CurrentPlayerHealth.Value)); core.DamageObservable .Where(_ => canSufferDamage) .Subscribe(x => ChangeHealth(-x.DamageValue)); CurrentPlayerHealth.Where(x => x <= 0) .FirstOrDefault() .Subscribe(_ => core.SetPlayerAliveReactiveProperty = false); }
public void Initialization() { _currentPlayerMove = Object.FindObjectOfType <CurrentPlayerMove>(); _currentPlayerHealth = Object.FindObjectOfType <CurrentPlayerHealth>(); }