/* * ------------------------------------------------------------------------ * Description: This class handles enemy health * Author: Eli Simpkins-Simmonds * ------------------------------------------------------------------------ */ using UnityEngine; public class EnemyHealth : MonoBehaviour { public int maxHealth = 100; // Maximum health of the enemy private int currentHealth; // Current health of the enemy public GameObject itemDropPrefab; // Prefab for the item to drop upon death void Start() { currentHealth = maxHealth; // Initialize current health to maximum health } public void TakeDamage(int damage) { currentHealth -= damage; // Reduce the current health by the damage amount if (currentHealth <= 0) // Check if the enemy's health is depleted { Die(); // Call the Die method to handle the enemy's death } } void Die() { DropItem(); // Spawn an item drop at the enemy's position Destroy(gameObject); // Destroy the enemy game object } void DropItem() { // Instantiate the item drop prefab at the enemys position Instantiate(itemDropPrefab, transform.position, Quaternion.identity); } }