public void HealthRegeneration()
 {
     Health += HealthRegenerationPerSecond * Time.deltaTime;
     if (Health > MaxHealth)
     {
         Health = Mathf.Clamp(Health, 0, MaxHealth);
     }
     OnHealthValueChanged?.Invoke(Health);
 }
        public void RespawnInitialization()
        {
            Health          = MaxHealth;
            Stamina         = MaxStamina;
            IsAfterActivity = false;
            IsTarget        = false;

            _restTimerCoroutine = RestTimer();
            _safeTimerCoroutine = SafeTimer();
            _isDying            = false;

            OnHealthValueChanged?.Invoke(Health);
            OnStaminaValueChanged?.Invoke(Stamina);
        }
Example #3
0
    private void Resurrect()
    {
        dead  = false;
        value = 100.0f;
        if (OnHealthValueChanged != null)
        {
            OnHealthValueChanged.Invoke(this);
        }

        Ragdoller ragdoller = GetComponent <Ragdoller>();

        if (ragdoller)
        {
            ragdoller.DisableRagdoll();
        }
    }
Example #4
0
    private void Die()
    {
        dead  = true;
        value = 0.0f;
        if (OnHealthValueChanged != null)
        {
            OnHealthValueChanged.Invoke(this);
        }

        Ragdoller ragdoller = GetComponent <Ragdoller>();

        if (ragdoller)
        {
            ragdoller.EnableRagdoll();
        }
    }
Example #5
0
    private void OnParticleCollision(GameObject g)
    {
        if (!dead)
        {
            value -= 15.0f * Time.deltaTime;

            if (value <= 0.0f)
            {
                StartCoroutine(DeathCoroutine());
            }

            if (OnHealthValueChanged != null)
            {
                OnHealthValueChanged.Invoke(this);
            }
        }
    }
        public void Hurt(float damage)
        {
            if (!photonView.IsMine)
            {
                return;
            }
            if (!IsAlive)
            {
                return;
            }

            // Update health value
            Health -= damage;

            // Clamp value if over the range
            if (Health < 0)
            {
                Health = Mathf.Clamp(Health, 0, MaxHealth);
            }

            // Notify listeners
            OnHealthValueChanged?.Invoke(Health);

            // Die if have no health
            if (Health == 0)
            {
                Death();
            }

            // Update IsTarget flag
            if (IsTarget)
            {
                StopCoroutine(_safeTimerCoroutine);
                _safeTimerCoroutine = SafeTimer();
            }
            else
            {
                IsTarget = true;
            }
            StartCoroutine(_safeTimerCoroutine);
        }
Example #7
0
 public void AddHealth(int value)
 {
     OnHealthValueChanged?.Invoke(value, playerModel.health + value);
     playerModel.health += value;
     healthView.AddHealth(value);
 }