Attack animation difficulties

Hey guys! I am fairly new to Unity and am working on a 2d game. It is fairly simple; the player moves the character in a side scroller format and can attack enemies. I have the movement and attack animation done; my character can stay idle, run, jump, and attack. However, when I attack midrun, my character keeps sliding and the animation goes to attack. Any tips or advise on how to fix this?

Unsure, but if you’re using the Animator, perhaps your transitions have a Transition Duration that isn’t 0? They default to 0.25, which is intended to blend between 3D animations, but if you are using sprites that’s not what you want - you want a sharp cut from one to the other, so that value needs to be 0. Check your transition links in the inspector, open the ‘Settings’ dropdown, and look at the Transition Duration value.

You’re actually forgetting to add an animation for midrun and transition to it from run.
Else if you’d like the char to stop when attack is hit, make another transition to idle, where you have your attack transition setup

u can write this after move

else if (myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack"))
            myrigidbody.velocity = new Vector2(0, 0);

that set your RB velocity 0 wen its attacking