Need help - Attack animation

Hi
I’ve been following the Hack and Slash tutorial from Burg Zerg Arcade, and have up untill now been able to solve all of my problems. But i’ve finished it now and thrown myself into practicing my own coding skills. But i encountered a problem that i can’t seem to solve.

I want to have my character play an attack animation, so i wrote this:

if(Input.GetButtonDown(“Actionbutton 1”)) {
SendMessage(“PlayMeleeAttack”);
}

the message is then recieved in another script file:

public void PlayMeleeAttack() {
Debug.Log( “*** Melee Attack Animation ***” );

animation[ meleeAttack.name ].wrapMode = WrapMode.Once;

if( meleeAttack == null ) {
Debug.LogWarning( “We need an animation clip for this script!” );
return;
}

Debug.Log( "Length: " + meleeAttack.length );
Debug.Log( "Speed: " + animation[ meleeAttack.name ].speed );

animation[ meleeAttack.name ].speed = animation[ meleeAttack.name ].length / 2f;
Debug.Log( "Speed: " + animation[ meleeAttack.name ].speed );

animation.Play( meleeAttack.name );
}

Now, i know it recieves the message because i can see it ingame, but the animation is not playing correctly.
It’s like he raises his hand, about to attack, and then stops and goes back to idle.

Please help, let me know if u need more info

You need to have the animation frames correct in the animation box (where you can say frame 30 to 50)
And you can manipulate the speed of the animation in script.
You also need to turn off the input of the player during the animation so it won’t get cut of.

animation["melee"].wrapMode = WrapMode.Once;
		animation["melee"].speed = 1.3;
		animation.CrossFade("melee");

You also need to set the layers of the animation:

animation["melee"].wrapMode = WrapMode.Once;
	animation["jump"].wrapMode = WrapMode.Once;
	animation["left"].wrapMode = WrapMode.Once;
	animation["right"].wrapMode = WrapMode.Once;
	
	animation["idle"].layer = 1;
	animation["run"].layer = 1;
	animation["back"].layer = 1;
	animation["jump"].layer = 2;
	animation["left"].layer = 2;
	animation["right"].layer = 2;
	animation["melee"].layer = 3;