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); } }
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); } } }