Example #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!collision.CompareTag("Enemy") && !collision.CompareTag("Projectile") && !collision.CompareTag("Powerup"))
        {
            PlayerTarget target = collision.transform.GetComponent <PlayerTarget>();

            if (target != null)
            {
                target.TakeDamage(damage);
            }

            Destroy(this.gameObject);
        }
    }
Example #2
0
    private void damageAndPushPlayer(Collider2D collider)
    {
        if (collider.CompareTag("Player"))
        {
            PlayerTarget target = collider.transform.GetComponent <PlayerTarget>();

            if (target != null)
            {
                target.TakeDamage(impactDamage);
                // pushing the player away from the enemy
                collider.transform.GetComponent <Rigidbody2D>().AddForce(calculateNormalizedCollisionVector(collider.transform) * impactForce);
            }
        }
    }