Hey everyone ive been getting a problem where I have a walk animation and an attack animation on the same object (sword)
For some reason when I walk and use the attack button the swing animation I use bugs out with the walking animation.
Is there a way to stop one animation while another plays? With my game its pretty important that the swing happens at the moment the button is pressed. I’ve tried a few things but the code I have up to now doesn’t work.
var sword : GameObject;
function Start() {
// Set all animations to loop
sword.animation.wrapMode = WrapMode.Loop;
// except shooting
sword.animation["attack1"].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.
sword.animation["attack1"].layer = 1;
// Stop animations that are already playing
//(In case user forgot to disable play automatically)
sword.animation.Stop();
}
function Update() {
// Based on the key that is pressed,
// play the walk animation or the idle animation
if (Input.GetAxis("Vertical"))
sword.animation.CrossFade("walk");
else if(Input.GetAxis("Horizontal"))
{
sword.animation.Play("walk");
}
// Shoot
if(Input.GetMouseButtonDown(0))
sword.animation.CrossFade("attack1");
}