Exemplo n.º 1
0
    public virtual void Damage(Damage damage)
    {
        if (IsDead)
        {
            return;
        }

        GotHit = true;

        if (sendFurther && reciever)
        {
            reciever.Damage(damage);
            return;
        }

        damage.amount  = Mathf.Min(damage.amount, CurrentHealth);
        CurrentHealth -= damage.amount;
        GameEventHandler.TriggerDamageDone(damage.other.GetComponent <PlayerController>(), damage);
        healthBar.UpdateBar(CurrentHealth, MaxHealth);

        if (CurrentHealth <= 0)
        {
            IsDead = true;
            Die();
        }
    }
Exemplo n.º 2
0
    private void Hit(GameObject other, Vector3 position)
    {
        if (other && other.GetComponent <HitAble>())
        {
            if (gameObjectHitted.Contains(other))
            {
                return;
            }

            HitAble target = other.GetComponent <HitAble>();
            target.Damage(new Damage()
            {
                DamageFromAPlayer = true,
                player            = player,
                amount            = damage,
                type  = DamageType.RANGED,
                other = player.transform
            });
            target.Hit(position, rigidbody2D.velocity * Time.fixedDeltaTime, force);

            gameObjectHitted.Add(other);

            AudioEffectController.Instance.PlayOneShot(HitEffect, transform.position);
        }
        else
        {
            EntitySpawnManager.InstantSpawn(hitEffektPoolName, position, Quaternion.identity, countEntity: false);

            EntitySpawnManager.Despawn(poolName, gameObject, false);
            return;
        }


        EntitySpawnManager.InstantSpawn(hitEffektPoolName, position, Quaternion.identity, countEntity: false);

        if (pierceCount >= pierceAmount)
        {
            rigidbody2D.velocity = Vector2.zero;
            GameObjectPool.Instance.Despawn(poolName, gameObject);
        }
        else
        {
            pierceCount++;
        }
    }