Example #1
0
    public virtual void OnTriggerEnter2D(Collider2D other)
    {
        ShooterEntity shooter = other.gameObject.GetComponent <ShooterEntity>();

        if ((shooter != null && shooter.type != this.type && ownerPool) || other.gameObject.tag == "shootLimit")
        {
            if (shooter != null && shooter.type == CharacterType.npc && this.type == CharacterType.player)
            {
                return;
            }
            if (ownerSpawner)
            {
                ownerSpawner.DeleteCurrentShoot(this.gameObject);
                ownerSpawner = null;
            }
            ownerPool.RecycleObject(this.gameObject);
        }
    }
    protected virtual void OnTriggerEnter2D(Collider2D other)
    {
        if (currentHealth <= 0)
        {
            return;
        }
        ShootBaseEntity shootEntity  = other.gameObject.GetComponent <ShootBaseEntity>();
        ShooterEntity   otherShooter = other.gameObject.GetComponent <ShooterEntity>();

        if (other.gameObject.tag == "shoot" && shootEntity != null)
        {
            switch (this.type)
            {
            case CharacterType.npc:
            case CharacterType.player:
                if (shootEntity.type == CharacterType.enemy)
                {
                    // NPC BEHAVIOUR
                }

                break;

            case CharacterType.enemy:
                if (shootEntity.type == CharacterType.npc || shootEntity.type == CharacterType.player)
                {
                    // Critical
                    float baseDamage = shootEntity.damage;
                    bool  isCritical = false;
                    if (Utils.GetRand01() < 0.09f)
                    {
                        baseDamage *= 1.8f;
                        isCritical  = true;
                    }
                    // Health reduction
                    currentHealth -= (int)Mathf.Ceil(baseDamage);
                    PlayDamageHit();


                    if (enemyInterface != null)
                    {
                        enemyInterface.OnHit();
                    }
                    if (_bar)
                    {
                        _bar.ReduceHealthBar(currentHealth, totalHealth);
                    }
                }

                break;

            default:
                break;
            }
        }
        else if (otherShooter != null && otherShooter.type == CharacterType.enemy && (this.type == CharacterType.player || this.type == CharacterType.npc))
        {
            if (otherShooter.damageByCollision > 0)
            {
                currentHealth -= otherShooter.damageByCollision;
                PlayDamageHit();
                if (enemyInterface != null)
                {
                    enemyInterface.OnHit();
                }
                if (_bar)
                {
                    _bar.ReduceHealthBar(currentHealth, totalHealth);
                }
            }
        }
        if (currentHealth <= 0 && hitableInterface != null)
        {
            EntityDestroy();
        }
    }