/* * ------------------------------------------------------------------------ * Description: This class handles the enemy damage system * Author: Eli Simpkins-Simmonds * ------------------------------------------------------------------------ */ using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyAttack : MonoBehaviour { public int damage = 20; // Amount of damage the enemy deals to the player // Method to deal damage to the player public void DealDamage() { // Find the player game object by its tag GameObject player = GameObject.FindWithTag("Player"); if (player != null) // Check if the player game object was found { // Get the PlayerHealth component from the player game object PlayerHealth playerHealth = player.GetComponent(); if (playerHealth != null) // Check if the PlayerHealth component exists { // Call the TakeDamage method on the PlayerHealth component to inflict damage playerHealth.TakeDamage(damage); } } } }