Stopping user input during attack state

I don’t understand the best method for stopping all input when having my character attack. The functionality I’m looking for is that when my character attacks, they can do nothing else. I want it this way so that attacks are meaningful and have consequence. When you commit you commit. I can’t quite get what I want.

The attack animation is about .3 seconds. The yeild I see recommend in many threads doesn’t work the way Intend. It stops players from putting input for .3 seconds, but it doesn’t start playing the animation until after that window.

I’ve tried checking the animator state, but it looks like delays in it transitioning to the state make it hard to depend on that. It looks like the crux of the issue is that the player state is being set back to walk before the animation ends, but I’m not sure how to prevent it. I’m pretty new to this library and this is really stumping me. I figure for now I can live with it and try and work on other systems, but I’d love some advice about the proper way to handle this kind of scenario.

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

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] public float moveSpeed = 5f;

    [SerializeField] Rigidbody2D rigidbody;

    [SerializeField] Animator animator;

    public PlayerState currentState;

    public enum PlayerState
    {
        walk,
        attack,
        interact
    }

    Vector2 movement;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Attack1") && currentState != PlayerState.attack)
        {
            currentState = PlayerState.attack;
        }

        if(currentState != PlayerState.attack) {


            if ((Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
                && (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f))
            {
               movement.x = Input.GetAxisRaw("Horizontal");
               movement.y = 0;
               currentState = PlayerState.walk;
            } else {
               movement.y = Input.GetAxisRaw("Vertical");
               movement.x = Input.GetAxisRaw("Horizontal");
               currentState = PlayerState.walk;
            }

            animator.SetFloat("Horizontal", movement.x);
            animator.SetFloat("Vertical", movement.y);
            animator.SetFloat("Speed", movement.sqrMagnitude); 

            if (Input.GetAxisRaw("Horizontal") == 1 ||
                Input.GetAxisRaw("Horizontal") == -1 ||
                Input.GetAxisRaw("Vertical") == 1 ||
                Input.GetAxisRaw("Vertical") == -1) {

                animator.SetFloat("LastHorizontal", Input.GetAxisRaw("Horizontal"));
                animator.SetFloat("LastVertical", Input.GetAxisRaw("Vertical"));
            }
        }

    }

    private void FixedUpdate()
    {
        if (currentState == PlayerState.walk)
        {
            rigidbody.MovePosition(rigidbody.position + (movement * moveSpeed * Time.fixedDeltaTime));
        } else if (currentState == PlayerState.attack)
        {
            StartCoroutine(AttackCo());
        }


    }

    private IEnumerator AttackCo()
    {
        AnimatorStateInfo currInfo = animator.GetCurrentAnimatorStateInfo(0);
        animator.SetBool("IsAttacking", true);
        currentState = PlayerState.attack;
        yield return null;

        yield return new WaitForSeconds(.3f);
        animator.SetBool("IsAttacking", false);
        currentState = PlayerState.walk;
    }
}

Might be an issue with some of the “exit time” in the animations, as Unity by default puts some “fading” from one anim to another (iirc). I’ve had to fiddle with things like this a lot (though it’s also bc I don’t fully understand it). I also found that using SetTrigger and ResetTrigger instead of bools helped in some cases. Here it would trigger the attacking animation, then automatically return to the previous state at the end. Might be worth a look.