private void OnCollisionEnter2D(Collision2D collision)
    {
        StatComponent otherStats = collision.gameObject.GetComponent <StatComponent>();

        if (otherStats != null)
        {
            otherStats.ModifyHealthBy(-Random.Range(myStats.minimumDamage, myStats.maximumDamage), myStats.damageMultiplayer);
        }
    }
Exemplo n.º 2
0
    private void PerformDamage(Collider2D collision)
    {
        if (Spawner != null)
        {
            if (Spawner == collision.gameObject)
            {
                return;
            }
        }

        if (collision.gameObject.tag == "Player" || collision.gameObject.tag == "Enemies")
        {
            StatComponent hitStat = collision.gameObject.GetComponent <StatComponent>();
            if (!hitStat.CanBeDealtDamage)
            {
                return;
            }

            switch (damageType)
            {
            case DamageType.Null:
                break;

            case DamageType.Enemy:
                if (collision.transform.position.y - 1f < transform.position.y)
                {
                    hitStat.ModifyHealthBy(-EnemyStats.damage, 1f);
                }
                else
                {
                    EnemyStats.ModifyHealthBy(-hitStat.damage, 1f);
                }
                break;

            case DamageType.Trap:
                hitStat.ModifyHealthBy(-trapDamage, 1f);
                break;

            case DamageType.Projectile:
                hitStat.ModifyHealthBy(-trapDamage, 0.1f);
                StopCoroutine(GetComponent <projectile>().DestroySelf(0f));
                StartCoroutine(GetComponent <projectile>().DestroySelf(0.1f));
                break;

            default:
                break;
            }

            if (trapType != TrapType.Rotating)
            {
                TempDisable();
            }
            else
            {
                foreach (DamageComponent dc in conjoinedTraps)
                {
                    dc.TempDisable();
                }
            }
            StartCoroutine(LaunchPlayer(hitStat.gameObject.GetComponent <Rigidbody2D>()));
        }
    }