Beispiel #1
0
 public virtual void ApplyDamage(float value, Unit source)
 {
     health -= value;
     if (health > 0)
     {
         ai?.OnDamageTaken(value, source);
         DamageApplied?.Invoke(this, value);
     }
 }
Beispiel #2
0
 public void ApplyDamage(int damage)
 {
     health = Mathf.Clamp(health - damage, 0, maxHealth);
     DamageApplied?.Invoke(new DamageAppliedEventArgs(damage, Card));
     if (health == 0)
     {
         //TODO add end of the game
         Debug.Log("GAME OVER!");
     }
 }
Beispiel #3
0
 public void ApplyDamage(int damage)
 {
     health = Mathf.Clamp(health - damage, 0, maxHealth);
     healthChanged.Invoke(health, maxHealth);
     DamageApplied?.Invoke(new DamageAppliedEventArgs((int)damage, this));
     if (health <= 0)
     {
         Die();
         return;
     }
     damageApplied.Invoke((int)damage, this);
 }
 public override void ApplyDamage(int amount)
 {
     if (_health - amount <= 0)
     {
         Die();
     }
     else
     {
         _health -= 1;
         Lives[_countLive].enabled = false;
         _countLive--;
         DamageApplied?.Invoke(amount);
     }
 }
Beispiel #5
0
    public override void ApplyDamage(int amount)
    {
        if (amount < 0)
        {
            return;
        }

        health -= amount;

        if (health <= 0)
        {
            Die();
        }
        DamageApplied?.Invoke(amount);
    }
        // Animation event
        public void Hit()
        {
            Vector2      attackDirection = Vector2.right * ((flip.isFacingRight) ? 1 : -1);
            Vector2      rayOrigin       = new Vector2(transform.position.x, transform.position.y + 0.5f);
            RaycastHit2D hit             = Physics2D.Raycast(rayOrigin, attackDirection, attackRange, layerMask);

            if (hit)
            {
                var target        = hit.transform.gameObject;
                var currentDamage = baseDamage;
                applyDamageModifiers?.Invoke(ref currentDamage);
                target.GetComponent <Health>().ApplyDamage(currentDamage);
                applyEffectsOnTarget?.Invoke(target);
                DamageApplied?.Invoke();
            }
        }
Beispiel #7
0
        // Animation event
        public void Hit()
        {
            var currentDamage = baseDamage;

            applyDamageModifiers?.Invoke(ref currentDamage);
            Vector2 centerInRelationUnitDirection =
                transform.position + applicationAreaCenter * ((flip.isFacingRight) ? 1 : -1);

            Collider2D[] enemiesInApplicationArea = Physics2D.OverlapBoxAll(
                centerInRelationUnitDirection,
                applicationArea,
                0f,
                layerMask);
            foreach (var enemie in enemiesInApplicationArea)
            {
                enemie.GetComponent <Health>().ApplyDamage(currentDamage);
                applyEffectsOnTarget?.Invoke(enemie.gameObject);
                DamageApplied?.Invoke();
            }
        }
Beispiel #8
0
 public void ApplyDamage(int damage)
 {
     OnDamageApplied(damage);
     DamageApplied?.Invoke(new DamageAppliedEventArgs(damage, Card));
 }