- Home /
Override animation with another
Hello, Thanks for viewing my question. I've been using Unity3D for 2 days, never scripted with javascript. I have 5 animations. Sword idle, Sword run, Sword run side, Sword attack, and Sword attack rightside. and the movement animations activate when you move horizontally, or vertically. The problem being, I can't use my sword attack or sword attack rightside while moving. I can attack if i stay still. Heres my script.
function Update() {
if(Input.GetMouseButtonDown(0))
animation.CrossFadeQueued("Sword_attack", 0.3, QueueMode.PlayNow);
// play sword attack when left click is pressed
if(Input.GetMouseButtonDown(1))
animation.CrossFadeQueued("Sword_attack_rightside", 0.3, QueueMode.PlayNow);
// play right side attack when right click is pressed
if(Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
// if moving forward or backward, play the running animation
animation.CrossFade("Sword_run", 0.2);
else
animation.PlayQueued("Sword_idle");
// if you aren't running, switch back to the idle animation.
if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
animation.CrossFade("Sword_run_side");
// if moving right or left, play the side step animation.
}
Can you guys help me at all?
Answer by Owen-Reynolds · Sep 08, 2012 at 03:21 PM
Look at the big animation page about layers, partial... and tricks to set up a system. Right now they are all on layer 0, so playing one will cancel anything else. Idle is working because PlayQueue specifically waits for Attack to finish.
Set the attack animation to layer 1+ and it will "win," covering up layer 0 animations while it plays.
Thank you, I just put all my attack animations into layers inside the code, i thought you meant literally putting it into a layer in the Project.
animation["Sword_attack"].layer = 1;
animation["Sword_attack_rightside"].layer = 1;
Your answer
Follow this Question
Related Questions
Animation Not Playing 1 Answer
1 FPS in Unity Timeline 0 Answers
How to change by-default fps in a 2D animation 3 Answers
Mecanim and double animations for a FPS 2 Answers
Animator doesnt work correctly after disabling then enabling a gameobject 1 Answer