Example #1
0
    private void Update()
    {
        if (invincibleTime >= 0f)
        {
            invincibleTime -= Time.deltaTime;
            if (invincibleTime <= 0f)
            {
                onInvincibilityChange.Invoke(false);
            }
        }
        if (recoveryCooldown > 0f)
        {
            recoveryCooldown -= Time.deltaTime;
        }
        else if (actualHitPoints < _hitPoints.second)
        {
            float delta  = Time.deltaTime * _recoveryRate;
            int   before = hitPoints.first;
            actualHitPoints = actualHitPoints + delta >= hitPoints.second ? hitPoints.second : actualHitPoints + delta;

            int intDelta = hitPoints.first - before;
            if (intDelta > 0)
            {
                onHPChange.Invoke(intDelta);
            }
        }
    }
Example #2
0
    public bool ConsumeSP(int cost)
    {
        if (cost > actualStamina)
        {
            return(false);
        }

        actualStamina   -= cost;
        recoveryCooldown = _recoveryStartupTime;
        onSPChange.Invoke(-cost);

        return(true);
    }