Character Sound Fx problems

hello, Im trying to create a sound Fx for my character such as walk, idle and jump sound.

here Is my script, not sure what I am doing is correct.

var SoundsEnabled = true;
var Ipin_Walk : AudioClip;
var Ipin_Jump : AudioClip;
var Ipin_Idle : AudioClip;

function Update () {

   if(animation.IsPlaying("walk") && SoundsEnabled == true)
   {
      if(audio.clip != Ipin_Walk)
        {
             audio.Stop();
             audio.clip = Ipin_Walk;
             audio.loop = true;
             audio.Play();
        }
   }

   if(animation.IsPlaying("jump") && SoundsEnabled == true)
   {
      if(audio.clip != Ipin_Jump)
        {
             audio.Stop();
             audio.clip = Ipin_Jump;
             audio.loop = true;
             audio.Play();
        }
   }   

   else if(animation.IsPlaying("idle") && SoundsEnabled == true)
   {
      if(audio.clip != Ipin_Idle)
        {
             audio.Stop();
             audio.clip = Ipin_Idle;
             audio.loop = true;
             audio.Play();
        }
   }

} 

as for now, my script kindda work. If I jump, walk and idle the sound will play accordingly. But when I started to walk and jump at the same time, my jump sound Fx did not play at all, only silent and when my charater land back on the ground from jumping it will play the walking sound Fx.

Having trouble with my jumping sound.

Could it be the problem, that unity tries to play both animations at the same time, so it constantly aborts the playing sound?

Maybe you could try to check if your character is grounded and use this boolean for playback?

Btw - you could exclude "&& SoundsEnabled == true", and ask it before entering all these ifs - makes you code a bit easier to read and to manage for yourself (and is probably faster, because if sounds are not enabled, you will only ask 1 condition instead of 4).

I'm not an Animation expert, and can't address that part, or grounding. But I can explain what @WiesenWiesel was saying about changing the SoundsEnabled part. He is suggesting that you add an if statement, like this:

function Update () {
    if (SoundsEnabled) // don't need the word true.
    {
        if (animation.IsPlaying("walk"))
        {
            // stuff here
        }
        if (animation.IsPlaying("jump"))
        {
            // stuff here
        }
        // and so on...
    }
}

This makes it a bit more readable. Though, if you really want to play with it, try moving the code into another function, like this:

function Update () {
    if (SoundsEnabled) // don't need the word true.
    {
        CheckAnimations();
    }
}

function CheckAnimations()
{
    if (animation.IsPlaying("walk"))
    {
        // stuff here
    }
    if (animation.IsPlaying("jump"))
    {
        // stuff here
    }
    // and so on...
}