AnimationScript help needed

Hello

I have one animation problem.
My animation is made of 4 elements : Idle, Walk, Shoot, Jump.
I don’t know if this is important to you but here is how these clips are set

Walk - Loop
Idle - Loop
Shoot - Once
Jump - Once

I have made AnimationScript that’s looking like this:

function Update () {

	if (Input.GetAxis("Walk"))
       animation.CrossFade ("Walk");
	else if (Input.GetAxis("Jump"))
       animation.CrossFade("Jump");
	else if (Input.GetAxis("Fire1"))
       animation.CrossFade("Shoot");	
  	else
      animation.CrossFade("Idle");
}

Here are some more axis settings:
Walk:
Positive Button: w
Negative Button: d
Alt Positive Button: up
Alt Negative Button: down
Jump:
Positive Button: space
Fire1:
Positive Button: joystick button 0

On the “Shoot” clip, only gun is moving and on the “Walk” clip, gun is not moving (it doesn’t change it’s transform)
When I hold “w” (the player walks forward) and when I press “Fire1”, the player continues walking (nothing about “Walk” clip changes) and the gun doesn’t move but when the “Idle” clip is playing and I press “Fire1”, “Shoot” clip playes.
I tryed writing “if” instead of “else if” but then only “Idle” clip is playing.

Please help me.

Thank you!!!

Probably, you wold want to take a look at animation blending for walking and shooting at the same time.

Is the gun attached to the player or are they two separate meshes? If they are separated, try to put them together. Otherwise, I would suggest that you take a look at the tutorial that Unity has on moving your character and shooting. You could take a look at the boot camp project that comes with Unity 3 as well.

Try putting the shoot animation in a higher layer than walk, in Start()… by default all animations are in layer 0, so:

Start(){
    animation["shoot"].layer = 1;
}

Should help.

But by having your if-else structure the way it is, if the player is walking, the shoot animation could never happen… because it will always be stuck in that first if block.

Try something like:

function Update () {

    if (Input.GetAxis("Walk"))
        animation.CrossFade ("Walk");
    else
        animation.CrossFade("Idle");
	
    if (Input.GetAxis("Fire1"))
        animation.CrossFade("Shoot");

      
}