Some animations aren't playing in Unity 3.4.2

Hello everyone,

I have a player character whose movement works just fine along both the horizontal and vertical axis. Moreover, the character’s walk animation works as expected, with all crossfading working as it normally would given that all the model’s animation wrap mode is loop. However, the character’s punch and kick animations are not playing at all when the relevant buttons are pressed. Here is my PlayerAttack.js script:

var punchSpeed = 1;
var punchHitTime = 0.2;
var punchTime = 0.4;
var punchPosition = new Vector3 (0, 0, 0.8);
var punchRadius = 1.3;
var punchHitPoints = 1;

var kickSpeed = 1;
var kickHitTime = 0.2;
var kickTime = 0.4;
var kickPosition = new Vector3 (0, 0, 0.8);
var kickRadius = 1.3;
var kickHitPoints = 1;

var bashSound : AudioClip;

private var busy = false; 

function Start ()
{
	animation["punch_r"].speed = punchSpeed;	
	animation["kick_r"].speed = kickSpeed;
}

function Update ()
{
	var controller : ThirdPersonController = GetComponent(ThirdPersonController); 
	if(!busy && Input.GetButtonDown("Punch"))
	{	
		SendMessage ("DidPunch");
		busy = true;
	}
	if(!busy && Input.GetButtonDown("Kick"))
	{	
		SendMessage ("DidKick");
		busy = true;
	}
}

function DidPunch ()
{
 Debug.Log("Punching...");
	animation.CrossFadeQueued("punch_r", 0.1, QueueMode.PlayNow);
	yield WaitForSeconds(punchHitTime);
	var pos = transform.TransformPoint(punchPosition);
	
	yield WaitForSeconds(punchTime - punchHitTime);
	busy = false;
}

function DidKick ()
{
Debug.Log("Kicking...");
	animation.CrossFadeQueued("kick_r", 0.1, QueueMode.PlayNow);
	yield WaitForSeconds(kickHitTime);
	var pos = transform.TransformPoint(kickPosition);
	
	yield WaitForSeconds(kickTime - kickHitTime);
	busy = false;
}

The Debug.Log() messages for each attack show up just fine in the console, so I’m 99% certain that it’s not a code issue. However, since I checked All Animations in Blender when I exported my .fbx file from Blender 2.5.7 to Unity 3.4.2, I can’t figure out how it can be an issue with my Blender file. Any and all help will be appreciated.

MachCUBED

I guess your animations work all on the same layer, therefore if you start one of your attack animations it propably gets directly overridden by your movement script. You should set your attack animations to a higher layer so they have a higher priority. If they are finished the movement animation will come back automatically.

Btw. Animation.CrossFadeQueued has some side effects due to duplicating the AnimationState. Only use it if you really need it. CrossFade should be enough in most cases.

Bunny83 and funky llama are right, fixing the Start() function in PlayerAttack.js like so:

`
function Start ()
{
	animation["punch_r"].speed = punchSpeed;	
	animation["kick_r"].speed = kickSpeed;
	
	animation["punch_r"].wrapMode = WrapMode.Once;
	animation["kick_r"].wrapMode = WrapMode.Once;
	
	animation["punch_r"].layer = 1;
	animation["kick_r"].layer = 1;
}
`

Fixed everything. Now, the attack animations work as they should. Thank you guys for the help!