voglio che venga risolto il fatto che l' enemy, una volta che il player entra nell area di attacco dell' enemy, attacca in rapida successione (quindi senza rispettare un cooldown), senza più fermarsi anche quando il player non è più all' interno dell' area di attacco, l' animazione dell' attacco viene fermata solo nel caso il player attacca e colpisce l enemy. i codici che si riferiscono a questo comportamento sono i seguenti:"using UnityEngine;
using UnityEngine.AI;
using System.Collections;

public class ChaseEnemy : MonoBehaviour
{
    public Transform target;
    protected NavMeshAgent agent;
    protected SpriteRenderer spriteRenderer;
    public Animator animator;

    protected Coroutine attackCoroutine;

    public Transform attackPoint;
    public float attackRange = 2f;
    public LayerMask targetLayers;

    public float chaseRange = 10f;
    public float attackCooldown = 1.5f;
    public int attackDamage = 10;

    protected Vector3 attackPointOffset;

    public float wanderRadius = 5f;
    public float wanderCooldown = 3f;
    protected float wanderTimer = 0f;

    protected virtual void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        spriteRenderer = GetComponent<SpriteRenderer>();
        animator = GetComponent<Animator>();
        attackPointOffset = attackPoint.localPosition;
        wanderTimer = wanderCooldown;
    }

    protected virtual void Update()
    {
        if (target == null) return;

        float distance = Vector3.Distance(transform.position, target.position);

        if (distance <= chaseRange)
        {
            if (distance > attackRange)
            {
                StopAttackCoroutine();
                ChaseTarget();
            }
            else
            {
                agent.ResetPath();
                AttackBehavior();
            }

            FlipSprite();
        }
        else
        {
            
            Wander();
        }
    }

    protected virtual void ChaseTarget()
    {
        if (agent != null && target != null)
        {
            agent.SetDestination(target.position);
            animator.SetBool("running", true);
        }
    }

    protected virtual void AttackBehavior()
    {
        animator.SetBool("running", false);

        if (attackCoroutine == null)
        {
            attackCoroutine = StartCoroutine(AttackRoutine());
        }
    }

    protected virtual IEnumerator AttackRoutine()
    {
        while (true)
        {
            Attack();
            yield return new WaitForSeconds(attackCooldown);

            float distance = Vector3.Distance(transform.position, target.position);
            if (distance > attackRange || target == null) break;
        }

        attackCoroutine = null;
    }

    protected virtual void Attack()
    {
        animator.SetTrigger("attack");
        
        Collider[] hitTargets = Physics.OverlapSphere(attackPoint.position, attackRange, targetLayers);

        foreach (Collider hitTarget in hitTargets)
        {
            if (hitTarget.TryGetComponent<PozzoHealth>(out PozzoHealth targetHealth))
            {
                targetHealth.takeDamage(attackDamage);
            }
        }
    }

    // Modifica qui: aggiungi 'virtual' al metodo FlipSprite
    protected virtual void FlipSprite()
    {
        Vector3 direction = target.position - transform.position;
        if (direction.x < 0)
        {
            spriteRenderer.flipX = false;
            attackPoint.localPosition = new Vector3(-Mathf.Abs(attackPointOffset.x), attackPointOffset.y, attackPointOffset.z);
        }
        else if (direction.x > 0)
        {
            spriteRenderer.flipX = true;
            attackPoint.localPosition = new Vector3(Mathf.Abs(attackPointOffset.x), attackPointOffset.y, attackPointOffset.z);
        }
    }

    protected virtual void StopAttackCoroutine()
    {
        if (attackCoroutine != null)
        {
            StopCoroutine(attackCoroutine);
            animator.ResetTrigger("attack");
            attackCoroutine = null;
        }
    }

    protected virtual void Wander()
    {
        wanderTimer += Time.deltaTime;
        if (wanderTimer >= wanderCooldown)
        {
            Vector3 newPos = RandomNavSphere(transform.position, wanderRadius, -1);
            agent.SetDestination(newPos);
            wanderTimer = 0f;
        }

        if (agent.velocity.magnitude > 0.1f)
        {
            animator.SetBool("running", true);
        }
        else
        {
            animator.SetBool("running", false);
        }
    }

    public static Vector3 RandomNavSphere(Vector3 origin, float dist, int layermask)
    {
        Vector3 randomDirection = Random.insideUnitSphere * dist;
        randomDirection += origin;
        NavMesh.SamplePosition(randomDirection, out NavMeshHit navHit, dist, layermask);
        return navHit.position;
    }

    protected virtual void OnDrawGizmosSelected()
    {
        if (attackPoint != null)
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere(attackPoint.position, attackRange);
        }

        Gizmos.color = Color.blue;
        Gizmos.DrawWireSphere(transform.position, chaseRange);
    }
}","using UnityEngine;
using System.Collections;

public class ChaseHumanEnemy : ChaseEnemy
{
    // Sovrascrivi FlipSprite per avere un comportamento diverso
    protected override void FlipSprite()
    {
        // Implementa qui la versione di FlipSprite specifica per ChaseHumanEnemy

        Vector3 direction = target.position - transform.position;
        if (direction.x < 0)
        {
            spriteRenderer.flipX = true; // Invertito rispetto a ChaseEnemy
            attackPoint.localPosition = new Vector3(-Mathf.Abs(attackPointOffset.x), attackPointOffset.y, attackPointOffset.z);
        }
        else if (direction.x > 0)
        {
            spriteRenderer.flipX = false; // Invertito rispetto a ChaseEnemy
            attackPoint.localPosition = new Vector3(Mathf.Abs(attackPointOffset.x), attackPointOffset.y, attackPointOffset.z);
        }
    }

    // Sovrascrivi Attack per attaccare il giocatore anziché il pozzo
    protected override void Attack()
    {
        animator.SetTrigger("attack");

        Collider[] hitTargets = Physics.OverlapSphere(attackPoint.position, attackRange, targetLayers);

        foreach (Collider hitTarget in hitTargets)
        {
            if (hitTarget.TryGetComponent<playerHealth>(out playerHealth player))
            {
                player.takeDamage(attackDamage);
            }
        }
    }

    // Modifica necessaria: Sovrascrivi AttackRoutine per risolvere il problema del cooldown e dell'attacco infinito
    protected override IEnumerator AttackRoutine()
    {
        while (true)
        {
            // Controlla se il giocatore è ancora nell'area di attacco
            float distance = Vector3.Distance(transform.position, target.position);
            if (distance > attackRange || target == null)
            {
                attackCoroutine = null; // Imposta attackCoroutine a null
                yield break; // Esce dal coroutine per interrompere l'attacco
            }

            Attack(); // Esegui l'attacco

            yield return new WaitForSeconds(attackCooldown); // Aspetta il cooldown prima del prossimo attacco
        }
    }

    // Modifica necessaria: Sovrascrivi AttackBehavior per gestire correttamente il coroutine
    protected override void AttackBehavior()
    {
        // Evita di avviare multipli coroutine
        if (attackCoroutine == null)
        {
            attackCoroutine = StartCoroutine(AttackRoutine());
        }
    }

    // Assicurati che StopAttackCoroutine interrompa correttamente il coroutine
    protected override void StopAttackCoroutine()
    {
        if (attackCoroutine != null)
        {
            StopCoroutine(attackCoroutine);
            attackCoroutine = null;
            animator.ResetTrigger("attack");
        }
    }
}"