Transitioning between 2D animations by frame

I am having issues with Unity’s default 2D animation system, and am curious as to how I can achieve a desired behavior. Within my project, I am attempting to transition between my character’s “Run” animation and “Running Attack” animation to allow the character to smoothly attack while moving.

The way I’ve been looking at handling this is by creating 3 different animations- one normal run cycle, one version of the same cycle with the character drawing their weapon, and a third run cycle with the weapon drawn. This way when the player attacks, the sprite’s run cycle would play the next frame of the “Draw Weapon” cycle, then the next frame would be from the “Weapon Drawn” cycle, before returning to the original cycle.

Here is an image from an existing game illustrating what I mean:

64638-example.png

My issue is that I’m not sure exactly how to transition between animations on specific frames. I’ve considered using a blend tree, but I’m not quite sure it will achieve what I want.

So you have a run animation and a running attack animation. Create two states in the animation controller with the two animations in them and have them transition to each other.
Add a bool perimeter IsAttacking and one transition set the conditions to be IsAttacking to be true and the other to be IsAttacking to be false and add a script like this on to your player:

Animator anim;

private bool attacking;

void Start () {
	anim = GetComponent<Animator>();
}

	void Update (){

	    if (Input.GetKeyDown (KeyCode.Space)) 
		{

			anim.SetBool("IsAttacking", true);
	}

weell i had a isuees like that before, i recomend you to use bleend trees only to make things like movement, like if speed its less that 0.5 walk, else run.

its better use “Animation” for attack or things you need to know if has finished, you can set animation.playqued if you want make attack combos ,also you can get the normalized of that animation to do another stuff, like send a damage event when the normalized time reach to 1.

Also you can always make a list of sprites and make your own custom animation.