Animation Scripting Help

I have an animation script for my walk and idle animation, I also have an animation for my shoot and reload (all scripts are at the bottom). But I have this problem that if I have both scripts attached to my gun the animations clash and dont work properly. I haven’t done anything to the animation options on the gun inside the inspector window which I think I need to do, can anyone help me with this?

walk and idle script;

function Start(){



  animation["walk"].speed = 1;

  

  animation["idle"].speed = 0.5;

  

  animation.wrapMode = WrapMode.Loop;

}

function Update () {

if (Input.GetAxis(“Vertical”) > 0.2)

   animation.CrossFade ("walk");

else

  animation.CrossFade ("idle");

}

shoot script;

function Start () {

animation[“shoot”].speed = 2;

}

function Update () {

if(Input.GetButtonDown(“Fire1”)){

animation.Play(“shoot”);

}

}

reload script;

function Start () {

animation[“reload”].speed = 1;

}

function Update () {

if(Input.GetButtonDown(“r”)){

animation.Play(“reload”);

}

}

Try setting each animation to an appropriate layer.
For instance if you have a ready animation for your character, you will want that animation to run all the time in a loop, however, you will also need attack animations and being struck by enemies,etc , to play.
So if you set the attack animations to play once and set them to a higher level, they will get priority, and once they are done playing, the ready animation will resume.

For the above code I believe you would need to set idle animation to layer 1. Then the walk animation to layer 2. The walk animation would need to be set to PingPong, whilst the idle animation would be set to loop.

I recommend reading the documentation for the functions you're using.

When you call Animation.Play or Animation.CrossFade, it effects all the animations that are currently playing (on the same layer).

I am very new to animations, but a quick scan of the documentation suggests that the animations triggered by your code will constantly interrupt each other.

The code that you've shared will cause the idle animation to play every frame that the up button is not being pressed. Otherwise, the walk animation will play.

If you want your shoot and reload animations to play, you probably have to stop your walk/idle animation (and vice versa).