Trying to add shoot pose

Hello,

I have been using Unity about a week now and have managed to get the character running and in an idle state. I have further tried to add an aim animation which works but only when the added run and idle animations are disabled. Please can you help me?

#pragma strict

var speed = 3.0;
var rotateSpeed = 3.0;



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 ()

{

  // This var is using the CharacterController on your model 

  var controller : CharacterController = GetComponent (CharacterController);

 //Rotate around y -axis

    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

     //move forward / backwords Vertical

    var forward = transform.TransformDirection(Vector3.forward);

var curSpeed = speed * Input.GetAxis ("Vertical");

    controller.SimpleMove(forward * curSpeed);
    
    if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)
       animation.CrossFade ("run");
   else
      animation.CrossFade ("idle");
    
 if (Input.GetButtonDown("Fire1"))
 animation.CrossFade("shoot");
 
}
@script RequireComponent(CharacterController)

You problem is that every Update you are setting either Idle or Run = so even when you set the Shoot animation, the next frame you cancel it by showing Idle or Run again…

OK I have got the script down a bit and the animation works but when he does the grenade animation (it is grenade now), it carries on sliding if going forward but without the run animation.

#pragma strict

var speed = 5.0;
var rotateSpeed = 3.0;

function Update()
{
// Uses Unity’s Character Controller Helper
var controller : CharacterController = GetComponent(CharacterController);

// rotate y
transform.Rotate(0, Input.GetAxis(“Horizontal”) * rotateSpeed, 0);

// fwd bwd
var forward = transform.TransformDirection(Vector3.forward); //down
var curSpeed = speed * Input.GetAxis(“Vertical”);
controller.SimpleMove(forward * curSpeed);

if (Input.GetAxis(“Vertical”) > 0.2 || Input.GetAxis(“Vertical”) < -0.2)
animation.CrossFade(“run”);
else
animation.CrossFade(“idle”);

 if (Input.GetAxis("Fire1")){
 
 animation.Stop("Vertical");
 animation.Play("grenade");

}
}
//}
@script RequireComponent(CharacterController)