using UnityEngine; public class EnemyAttack : MonoBehaviour { [SerializeField] private float attackRange = 5f; [SerializeField] private float attackRate = 2f; [SerializeField] private float attackDamage = 10f; [SerializeField] private float attackAngle = 45f; private float lastAttackTime = 0f; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { } // Update is called once per frame void Update() { } private void FixedUpdate() { } private void OnTriggerEnter(Collider other) { } private void OnTriggerStay(Collider other) { var player = other.GetComponent(); if (player != null && Time.time - lastAttackTime > attackRate) { var health = other.GetComponent(); if (health != null) { health.ModifyHealth(-attackDamage); Debug.Log("Enemy attacked! Next attack in: " + (1f / attackRate) + " seconds"); lastAttackTime = Time.time; } } } private void OnTriggerExit(Collider other) { } }