Esempio n. 1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            Consume();
        }

        currentEnergy += rechargeRate * Time.deltaTime;

        if (currentEnergy > 1)
        {
            currentEnergy = 1;
        }

        energyBar.UpdateBar(currentEnergy);
    }
Esempio n. 2
0
    public void ChangeHealth(float amount)
    {
        CurrentHealth += amount;

        if (CurrentHealth > MaxHealth)
        {
            CurrentHealth = MaxHealth;
        }
        else if (CurrentHealth <= 0)
        {
            CurrentHealth = 0;
            if (isDead)
            {
                return;
            }
            isDead = true;
            OnDeath?.Invoke();
        }

        if (healthBar != null)
        {
            healthBar.UpdateBar((float)CurrentHealth / (float)MaxHealth);
        }
    }