Animation Scripting - Help needed in a hurry

So I have some animations which animate to what my player is doing.

Etc if he stands still, the sword stands still / if the player walks the sword animates “walking”.

And when i press Mouse button 1 it animates the sword “attacking”.

So when i walk and then press Mouse button 1 it attacks while i walk and when i stand still it also attacks when i press the key.

But now to the problem, when i use the “Sprint” animation which i toggled by “LeftShift” and then Press Mouse button 1, it just looks stuck, like its trying to execute the "Attack command but it can´t because the "Sprint animation is blocking it…

Here is my code, help please :slight_smile:

function Update	()
{
	if (Input.GetButtonDown("Fire1"))
	{
		//Attack animation
		TheSword.animation.Play("Attack");
		//Attack function
		var hit : RaycastHit;
		if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
		{
			Distance = hit.distance;
			if (Distance < MaxDistance) 
			{
				hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
			}
		}
	}
	if (TheSword.animation.isPlaying == false)
	{
		TheSword.animation.CrossFade("Walk");
	}	
	
	if (Input.GetKey(KeyCode.LeftShift))
	{
		TheSword.animation.CrossFade("Sprint");
	}
	
	if (Input.GetKeyUp(KeyCode.W))
	{
		TheSword.animation.CrossFade("Stand");
	}
	
	if (Input.GetKey(KeyCode.W)(Input.GetKey(KeyCode.LeftShift)))
	{
		TheSword.animation.CrossFade("Sprint");
	}
}

It might be because the CrossFade to “Sprint” is executed every frame, again and again. You should do a check to see if it’s already playing :wink: Like you did for the “Walk” :slight_smile:

i didn´t make a check with the Walk, i made a check with the Fire1 :slight_smile:

And i dont really know what to do now :3

You misunderstood him completely. The thing you are doing is a if-check for Fire1, THEN watch for sprint etc.
Besides, that you should use mecanim, because it is as far as I used it much more powerful and userfriendly(And thus it can even blend Animations together), it is the same Idea behind:
First check the irrevelant Animations, then check the important/interruptive.
The Problem at you End is: It checks if Fire 1 is pressed → Executes the Attack Animation. THEN it sees, it is Sprinting also, so it blends the Sprintanimation. You now see the Problem?

It is just a matter of rethinking the Order of execution in your script.