Shooting Animation Won't Work Please Help

Alright I’m having a problem with the animation for my character. Everything works except for the shooting animation.

I’ve tried everything for hours and I can’t get it working. I even put the shooting animation as the idle to make sure it was working and it did. For some reason the shoot call isn’t working even though it worked fine on my other character.

I have the script here so if someone can take a look and tell me what I’m doing wrong it’d be much appreciated.

Thanks

function Start ()
{
   // Set all animations to loop
   animation.wrapMode = WrapMode.Loop;
   // except shooting
   animation["shoot"].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["shoot"].layer = 1;
   // Stop animations that are already playing
   //(In case user forgot to disable play automatically)
   animation.Stop();
}

function Update () {
   // Based on the key that is pressed,
   // play the walk animation or the idle animation
   if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
      animation.CrossFade("walk");
   else
      animation.CrossFade("idle");
	  
	  if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
      animation.CrossFade("side");
	  
   // Shoot
   if (Input.GetButtonDown ("Fire1"))
            animation.CrossFade("shoot");

}

How long is your shoot animation? Crossfade defaults to taking 0.3 seconds to fade in, if it’s very short, and isn’t set to loop you might never see it.

Although if it did loop then it’d get stuck “on”, which probably isn’t what you want either, you’d want something like :

   // Shoot 
   if (Input.GetButton ("Fire1")) 
            animation.Play("shoot");
   else
            animation.Stop("shoot");

Thank you so much it worked!

Real quick would you know how to add a bullet tracer to the FPS machine gun script? Just like use a small line render? Thanks