Playing animations problem

Ok, for a while I’ve had my animations down. Had idle playing when idle, walk playing when walking, and run playing when running. However I just started to add special animations like attacking, etc., and I cannot get it to work properly.

The root of the problem is that I cannot get my attack animation to play/play fully. It does the very first frame, and then returns to the basic 3 animations, or it just doesn’t play at all.

I know that does work though because I replaced idle with my “swordSlash” animation and it was able to play continuously when I was standing still.

I had the original 3 animations incorporated into my platformer controls script, but decided to do it in a new “animations” script.

I tried a variety of things, including crossfading, and a number of different types if/else statements.

I don’t know if I am taking the wrong approach or something, if so, could you enlighten me?

The current problems with the setup I pasted below is that nothing plays when I hit Fire1 or when I try to run

function Start (){
   // Set all animations to loop
   animation["walk"].wrapMode = WrapMode.Loop;
   animation["run"].wrapMode = WrapMode.Loop;
   animation["idle"].wrapMode = WrapMode.Loop;
   // except shooting
   animation["swordSlash"].wrapMode = WrapMode.Once;

   // Put idle and walk into lower layers (The default layer is always 0)
   // This will do two things
   // - Since shoot and idle/walk are in different layers they will not affect
   //   each other's playback when calling CrossFade.
   // - Since shoot is in a higher layer, the animation will replace idle/walk
   //   animations when faded in.
   animation["swordSlash"].layer = 1;

   // Stop animations that are already playing
   //(In case user forgot to disable play automatically)
   animation.Stop();
}






 function Update () {


if(Input.GetButton("Fire1")){
	Debug.Log("Fire1 button pressed");
	animation.CrossFade("swordSlash");
	Debug.Log("swordSlash animation supposedly began");
	}else{
		if(Input.GetAxis("Horizontal")){
			if(Input.GetButtonDown("Run")){
			 	Debug.Log("Run command was pressed");
				animation.CrossFade("run");
				Debug.Log("run animation supposedly began");
			}else{
				Debug.Log("Horizontal axis is not pressed");
				animation.CrossFade("walk");
				Debug.Log("walk animation supposedly began");
			}
	}else{
		Debug.Log("Fire1 button isn't being pressed");
		animation.CrossFade("idle");
		Debug.Log("idle animation supposedly began");
	}
}
}

edit: correction… the swordSlash animation plays the first frame in the pasted(and current) version of the code then returns immediately to idle

edit2: did extensive debug, and it recognizes that run was pressed the first update cycle that it is pressed, but not while its held, and it recognizes that the swordSlash button was pressed, but it doesn’t play the run animation at all, and it seems that swordSlash gets “stopped” by the update walk/idle (and edited current code in)

edit3: got run animation fixed by changing getButtonDown to getButton

ALRIGHT! I fixed it!!

Don’t know if this is just temporary since I will have more animations to add later, but all I had to do was change the

animation.CrossFade("swordSlash"); 

to

animation.Play("swordSlash");

and everything works fine!!!

Answered my own damn question.