コード例 #1
0
    public void TakeDamage(int attackDamage)
    {
        enemyStatistics.HealtPoints -= attackDamage;
        OnTakenDamage?.Invoke((float)attackDamage / (float)enemyStatistics.MaxHealtPoints, enemyStatistics.HealtPoints);

        if (enemyStatistics.HealtPoints == 0)
        {
            Die();
            boxCollider2D.enabled = false;
        }
    }
コード例 #2
0
    public void Damage(float f)
    {
        OnTakenDamage?.Invoke(f);
        health -= f;

        if (health <= 0f)
        {
            health = 0f; //minimum health
            if (!isDead) //call OnDeath when the entity dies

            {
                OnDeath?.Invoke(destroyOnDeath);

                isDead = true;
            }
        }
    }
コード例 #3
0
    private void CheckDamage(GameObject damagerGo)
    {
        if (!rb.IsTouchingLayers(collideableLayersMask) || isInvincible)
        {
            return;
        }

        var dd = damagerGo.GetComponent <IDamageDealer>();

        if (dd != null && dd.GetDamage() > 0f)
        {
            if (healthSystem.GetHealth() > 0)
            {
                OnTakenDamage?.Invoke();
            }
            healthSystem.Damage(dd.GetDamage());
            OnDamagedBy?.Invoke(damagerGo);
            isInvincible = true;
            coroutines.WaitThenExecute(invincibleDuration, () => StopInvincibility());
        }
    }