Esempio n. 1
0
    /// <summary>
    /// When colliding with player projectiles, take damage if it hasn't been hit by it yet.
    /// </summary>
    /// <param name="otherCollider"></param>
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        Projectile projectile = otherCollider.gameObject.GetComponent <Projectile>();

        if (projectile == null)
        {
            Debug.Log("Null");
            return;
        }
        if (projectile.isEnemy)
        {
            return;
        }

        if (!projectile.AddHitID(group.enemyId))
        {
            return;
        }

        if (invincibleEnemy.value)
        {
            return;
        }

        group.TakeDamage(projectile.damage);

        Transform t = Instantiate(damageNumbers);

        t.position = transform.position;
        DamageNumberDisplay dnd = t.GetComponent <DamageNumberDisplay>();

        dnd.damage = projectile.damage;
        battleGUI.damages.Add(dnd);
        id++;
    }
    /// <summary>
    /// When hit by an enemy projectile, take damage and remove it.
    /// </summary>
    /// <param name="otherCollider"></param>
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        Projectile projectile = otherCollider.gameObject.GetComponent <Projectile>();

        if (projectile == null)
        {
            return;
        }

        if (!projectile.isEnemy)
        {
            return;
        }

        if (!projectile.AddHitID(0))
        {
            return;
        }

        if (!canBeHurt || invinciblePlayer.value)
        {
            return;
        }

        defense = playerDefense.value;
        int dmg = TakeDamage(projectile.damage);

        damageTaken.value += dmg;
        if (dmg > 0)
        {
            takenDamageEvent.Invoke();
            if (projectile.impactSound != null)
            {
                currentSfx.value.Enqueue(projectile.impactSound.clip);
            }
            if (Random.Range(0f, 1f) < hurtNoiseChance.value)
            {
                currentSfx.value.Enqueue(hurtNoises.RandomClip());
            }
            playSfxEvent.Invoke();
        }

        if (damageTaken.value + otherDamageTaken.value >= playerMaxHealth.value)
        {
            Die();
        }
    }
    /// <summary>
    /// When colliding with player projectiles, take damage if it hasn't been hit by it yet.
    /// </summary>
    /// <param name="otherCollider"></param>
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        Projectile projectile = otherCollider.gameObject.GetComponent <Projectile>();

        if (projectile == null)
        {
            Debug.Log("Null");
            return;
        }
        if (projectile.isEnemy)
        {
            return;
        }

        if (!projectile.AddHitID(group.enemyId))
        {
            return;
        }

        if (invincibleEnemy.value)
        {
            return;
        }

        group.TakeDamage((onehitKO.value) ? group.maxhp : projectile.damage);

        Transform t = Instantiate(damageNumbers);

        t.position = transform.position;
        DamageNumberDisplay dnd = t.GetComponent <DamageNumberDisplay>();

        dnd.damage = projectile.damage;
        battleGUI.damages.Add(dnd);
        id++;

        if (projectile.impactSound != null)
        {
            currentSfx.value.Enqueue(projectile.impactSound.clip);
            playSfxEvent.Invoke();
        }
    }
Esempio n. 4
0
    /// <summary>
    /// When hit by an enemy projectile, take damage and remove it.
    /// </summary>
    /// <param name="otherCollider"></param>
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        Projectile projectile = otherCollider.gameObject.GetComponent <Projectile>();

        if (projectile == null)
        {
            return;
        }

        if (!projectile.isEnemy)
        {
            return;
        }

        if (!projectile.AddHitID(0))
        {
            return;
        }

        if (!canBeHurt || invinciblePlayer.value)
        {
            return;
        }

        defense = playerDefense.value;
        int dmg = TakeDamage(projectile.damage);

        damageTaken.value += dmg;
        if (dmg > 0)
        {
            takenDamageEvent.Invoke();
        }

        if (damageTaken.value + otherDamageTaken.value >= playerMaxHealth.value)
        {
            Die();
        }
    }