Animation playing in loop

Hello, I am trying to make a game and i am now adding special attack where player will dash and then he will like pierce enemy with his sword, I have two problems with this 1st this attack is affecting basic attack. What i mean is that when i use basic attack i want it have delay but for the special attack I want it to have little bit more delay but I only know about Time.time command and it affect the basic attack so the basic attack has bigger delay when I use special attack then when I use basic attack. 2nd problem is that when I want to use the special attack, befor I added things like animation event it just did dmg right after the animation was played and not when the player got in contact with enemy. Then I tried to use animation event but only thing I reached was that the animation went to a Loop. Here is the code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class PlayerMovement : MonoBehaviour
{
    public Animator animator;

    public Transform attackPoint;

    public float attackRange = 0.5f;
    public int attackDamage = 40;
    public LayerMask enemyLayers;


    public float attackRate = 2f;
    float nextAttackTime = 0f;
    float nextComboAttackTime = 0f;

    private float horizontal;
    private float speed = 8f;
    private float jumpingPower = 32f;
    private bool isFacingRight = true;
    private bool inAir;

    private bool canDash = true;
    private bool isDashing;
    private float dashingPower = 150f;
    private float dashingTime = 0.2f;
    private float dashingCooldown = 1f;

    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private Transform groundCheck;
    [SerializeField] private LayerMask groundLayer;
    [SerializeField] private TrailRenderer tr;

    void Update()
    {

        animator.SetBool("IsDashing", isDashing);
        animator.SetFloat("Speed", Mathf.Abs(horizontal));
        animator.SetBool("IsJumping", inAir);

        if (isDashing)
        {
            return;
        }

        if (Time.time >= nextAttackTime)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Attack();
                nextAttackTime = Time.time + 1f / attackRate;
            }
        }

        if (Time.time >= nextComboAttackTime)
        {
            if (Input.GetKeyDown(KeyCode.H) && canDash)
            {
                StartCoroutine(Dash());
                ComboAttack();
                nextAttackTime = Time.time + 1f / attackRate;
            }
        }
        horizontal = Input.GetAxisRaw("Horizontal");

        if (Input.GetKeyDown(KeyCode.W) && IsGrounded())
        {
            inAir = true;
            rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
        }

        if (Input.GetKeyDown(KeyCode.W) && rb.velocity.y > 0f)
        {
            inAir = false;
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
        }

        if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
        {
            StartCoroutine(Dash());
        }

        Flip();
    }

    void Attack()
    {
        animator.SetTrigger("Attack");

        Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);

        foreach (Collider2D enemy in hitEnemies)
        {
            enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
        }
    }

    void ComboAttack()
    {
        animator.SetTrigger("ComboAttack");

        Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);

        foreach (Collider2D enemy in hitEnemies)
        {
            enemy.GetComponent<Enemy>().TakeDamage(attackDamage * 2);
        }
    }

    private void FixedUpdate()
    {
        if (isDashing)
        {
            return;
        }

        rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
    }

    private bool IsGrounded()
    {
        return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
    }

    private void Flip()
    {
        if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = transform.localScale;
            localScale.x *= -1f;
            transform.localScale = localScale;
        }
    }

    private IEnumerator Dash()
    {
        canDash = false;
        isDashing = true;
        float originalGravity = rb.gravityScale;
        rb.gravityScale = 0f;
        rb.velocity = new Vector2(transform.localScale.x * dashingPower, 0f);
        tr.emitting = true;
        yield return new WaitForSeconds(dashingTime);
        tr.emitting = false;
        rb.gravityScale = originalGravity;
        isDashing = false;
        yield return new WaitForSeconds(dashingCooldown);
        canDash = true;
    }
    void OnDrawGizmosSelected()
    {
        if (attackPoint == null)
            return;

        Gizmos.DrawWireSphere(attackPoint.position, attackRange);
    }
}

heres my code: The only thing though is that if there is no input after mouse0 the animation will be on the last frame until a new input is set up.
You could try disabling the loop pose within the animation itself.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class thirdPersonController : MonoBehaviour
  
 {private staminaManager staminaManager; // Reference to the StaminaManager
 private healthManager healthManager; // Reference to the healthManager
    public float speed = 5.0f;
  
public GameObject Player;
    public float rotationSpeed = 200.0f;
    public float jumpForce = 2.0f;
    public float sprintSpeed = 10.0f;
     private bool isJumping = false;
public float walkSpeed = 1.0f;
       
    public Animator animator; // Animator component

    public Rigidbody rb;
    public Rigidbody gsrb;
    public GameObject world;
  public KeyCode attackKey;
  public Transform Greatsword;
  public Transform player;
    void Start()
    {
        animator.enabled = true;
        animator.enabled = false;
        animator.enabled = true;
     staminaManager = FindObjectOfType<staminaManager>(); // Find the StaminaManager in the scene
       healthManager = FindObjectOfType<healthManager>(); // Find the healthManager in the scene
       gsrb.isKinematic = true;
       gsrb.useGravity = false;

    }
// kill if below map

    void FixedUpdate()
    {   KillAtZeroHealth();
    
    if (Player.transform.position.y <= -5.0f) {
      healthManager.currentHealth = 0.0f;
      animator.enabled = false;
    }
      
   

     
     //movemebt
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        
        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
            // movement
             if (Input.GetKey(KeyCode.LeftShift))
        {
            rb.AddForce(movement * sprintSpeed);
          animator.SetBool("Run", true); // Play the running animation
           // transform.Translate(Vector3.forward * Time.deltaTime * sprintSpeed);
        }
        else
        {
            rb.AddForce(movement * speed);
            animator.SetBool("Run", false); // Stop the running animation
           // transform.Translate(Vector3.forward * Time.deltaTime);
        }
       
        // Rotate the player to face the direction of movement
      //  if (movement != Vector3.zero)
      //  {
      //      Quaternion toRotation = Quaternion.LookRotation(movement, Vector3.up);
       //     transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
      //  }

        // Make the player jump if the jump button is pressed
        if (Input.GetButtonDown("Jump") && !isJumping)
        { if (staminaManager.currentStamina <= 15f)
            {rb.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);
            isJumping = true;
             staminaManager.UseStamina(15f);
              animator.SetTrigger("Jump"); // Play the jump animation
            }        
        }
        
           float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");
    bool Walk = Mathf.Abs(horizontalInput + verticalInput) > 0.1f;
       if (Input.GetKey(KeyCode.LeftShift))
        {
          animator.SetBool("Run", true); // Play the running animation
       transform.Translate(Vector3.forward * Time.deltaTime * sprintSpeed * verticalInput);
      void Update(){
       staminaManager.currentStamina = staminaManager.currentStamina - (10.0f * Time.deltaTime);
      }
         }
        
        else {
            transform.Translate(Vector3.forward * Time.deltaTime * speed * verticalInput);
        }
		// Rotation
		transform.Rotate(Vector3.up, rotationSpeed * horizontalInput * Time.deltaTime);
 

    animator.SetBool("Walk", Walk);
    animator.SetFloat("Speed", (horizontalInput + verticalInput) * walkSpeed);
    // attacking
    AttackOnCLick();
    }

    // Detect collision with the ground
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Ground"))
        {
            isJumping = false;
        }
    }
    void KillAtZeroHealth()
    {
   if (healthManager.currentHealth <= 0){
     healthManager.ShowYouDied();
        animator.SetTrigger("isDead"); // Play the dying animation
      
       // animator.enabled = false;
          healthManager.ShowYouDied();
          //drop sword
          Greatsword.SetParent(player);

   gsrb.isKinematic = false;
       gsrb.useGravity = true;
 
          GetComponent<thirdPersonController>().enabled = false; // Disable this script
         }
     else {
      animator.enabled = true;
     }
    }
     public void AttackOnCLick(){if (Input.GetKeyDown(attackKey))
        { if (staminaManager.currentStamina >= 15.0f){
              animator.SetTrigger("Attack"); // Play the attack animation
                // Reduce stamina (example: decrease by 10 units)
            staminaManager.UseStamina(15f);
        }
        }
     }
}