Stop animation at the current frame

The character currently has two states, walking and idle. idle state is just a single sprite. walking animation has 4 sprites/frames. Currently I’m using this kind of code to play the animation

if(Input.GetKey(KeyCode.A) anim.SetBool("isWalking",true);
else //any other key or no key

When A key is released, the animation stops but only after playing the entire 4 frames. So it looks really odd since the walking animation stops after ~0.5 seconds after playing entirely. I want it to stop at whatever frame is being played when the key is released and immediately return to the idle state.

Go into the animator window and select the transition from walking to idle state. Then uncheck “Has exit time.” This will allow the transition to occur right when the condition for the transition is met, and not after the animation completes.