/* * ------------------------------------------------------------------------ * Description: This class handles projectile collison * Author: Eli Simpkins-Simmonds * ------------------------------------------------------------------------ */ using UnityEngine; public class ProjectileCollisionHandler : MonoBehaviour { public int damage = 10; void OnCollisionEnter2D(Collision2D collision) { GameObject collidedObject = collision.gameObject; // Check if the collided object is an enemy if (collidedObject.CompareTag("Enemy")) { // Apply damage to the enemy EnemyHealth enemyHealth = collidedObject.GetComponent(); if (enemyHealth != null) { enemyHealth.TakeDamage(damage); } // Destroy the projectile on collision Destroy(gameObject); } } }