Need help replicating the Zelda Gameboy games sword swinging

Hello,

As said in the title I currently am trying to replicate the way that the Zelda gameboy games handle sword swinging. The thing I am specifically struggling with is that you are able to spam the attack button to swing rapidly. This is shown in the beginning of this video:

This is currently what my PlayerController currently looks like:

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

public enum PlayerState {
    walk,
    attack,
    interact
}

public class PlayerMovement : MonoBehaviour
{
    public PlayerState currentState;
    public float speed;
    private Rigidbody2D playerRigidbody;
    private Vector3 change;
    private Animator anim;

    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent<Animator>();
        playerRigidbody = GetComponent<Rigidbody2D>();
        currentState = PlayerState.walk;
    }

    // Update is called once per frame
    void Update()
    {
        change = Vector3.zero;
        change.x = Input.GetAxisRaw("Horizontal");
        change.y = Input.GetAxisRaw("Vertical"); 
      

        if (Input.GetButtonDown("attack") && currentState != PlayerState.attack)
        {
            StartCoroutine(AttackCo());
        }
        else if (currentState == PlayerState.walk)
        {
            UpdateAnimationsAndMove();
        }
       
    }
    private IEnumerator AttackCo()
    {
        anim.SetBool("Attacking", true);
        currentState = PlayerState.attack;
        yield return null;
        anim.SetBool("Attacking", false);
        yield return new WaitForSeconds(0.25f);
        currentState = PlayerState.walk;
    }
    void UpdateAnimationsAndMove() {
        if (change != Vector3.zero)
        {
            MovePlayer();
            anim.SetFloat("movex", change.x);
            anim.SetFloat("movey", change.y);
            anim.SetBool("moving", true);
        }
        else
        {
            anim.SetBool("moving", false);
        }

    }
    void MovePlayer() {
        playerRigidbody.MovePosition(transform.position + change * speed * Time.deltaTime);
    }
}

This code recreates the base movement and sword swinging pretty closely, however you can’t attack quickly like shown in the video. Any suggestions on how I can implement this?

Thanks!

Sounds like it’s waiting for your animation to finish completely before playing it again? Does the animation take longer than 0.25s to play?

Yeah it does wait for it to finish completely. The animation is exactly 0.25s.

Just reset the animation from the start each time the user presses the swing button.

Also keep in mind the game you are referencing has a 2 - 3 frame swing animation. I’m guessing yours is a lot more frames.