- Home /
 
Audio says it is playing in audiosource but is not...
I have it so when i am idle, the idle sound plays and when im moving, moving sound plays, and my audio source does indeed switch sounds but doesn't play them...Help..
 var movingSound : AudioClip;
 var idleSound : AudioClip;
 var isIdle : boolean;
 var isMoving : boolean;
  
  
 function Update (){
        if (Input.GetKey("w") || Input.GetKey("s")
        || Input.GetKey("a") || Input.GetKey("d")){
               isMoving = true;
               isIdle = false;
        }else{
               isMoving = false;
               isIdle = true;
        }
        if (isMoving == true){
               
               audio.clip = movingSound;
               audio.Play();
        }else{
                  audio.clip = idleSound;
                  audio.Play();
      
        }
  
 }
 
              do you have audio listeners? also try this audio.Play(idleSOund); audio.Play(othersound);
Answer by whydoidoit · Mar 30, 2013 at 11:59 PM
You are calling the Play function every frame - which resets the sound to the starting position.
 var movingSound : AudioClip;
 var idleSound : AudioClip;
 var isIdle : boolean;
 var isMoving : boolean;
 var playingIdle : boolean;
  
  
 function Update (){
        if (Input.GetKey("w") || Input.GetKey("s")
        || Input.GetKey("a") || Input.GetKey("d")){
               isMoving = true;
               isIdle = false;
        }else{
               isMoving = false;
               isIdle = true;
        }
        if (isMoving == true){
               if(playingIdle)
               {
                 audio.clip = movingSound;
                 audio.Play();
                 playingIdle = false;
               }
        }else{
               if(!playingIdle)
               {
                 audio.clip = idleSound;
                 audio.Play();
                 playingIdle = true;
              }
  
        }
  
 }
 
              thank you I$$anonymous$$$$anonymous$$ENSELY! I have been working on this for a while and now it works!!! Thanks man
You're welcome :) I have to say it's one of those things it's really easy not to think about...
Also $$anonymous$$ike, can you please further explain this, as i am trying to implement a sprint sound too...
 var movingSound : AudioClip;
 var idleSound : AudioClip;
 var sprintSound : AudioClip;
 var isIdle : boolean;
 var is$$anonymous$$oving : boolean;
 var playingIdle : boolean;
 var isSprinting :boolean;
 var playing$$anonymous$$oving : boolean;
  
  
 function Update (){
        if (Input.Get$$anonymous$$ey("w") || Input.Get$$anonymous$$ey("s")
        || Input.Get$$anonymous$$ey("a") || Input.Get$$anonymous$$ey("d")){
               is$$anonymous$$oving = true;
               isIdle = false;
        }else{
               is$$anonymous$$oving = false;
               isIdle = true;
        }
        if (is$$anonymous$$oving == true){
               if(playingIdle)
               {
                 audio.clip = movingSound;
                 audio.Play();
                 playingIdle = false;
               }
        }else{
               if(!playingIdle)
               {
                 audio.clip = idleSound;
                 audio.Play();
                 playingIdle = true;
              }
         }
         if (Input.Get$$anonymous$$ey("left shift") && is$$anonymous$$oving){
             isSprinting = true;
        }else{
                isSprinting = false;
                }
             
             
         
         
             if (isSprinting == true)
                 if(playing$$anonymous$$oving)
                 {
                     audio.clip = sprintSound;
                     audio.Play(); 
                     playing$$anonymous$$oving = false;
                     
             }else{
                   if(!playing$$anonymous$$oving)
                   {
                     audio.clip = movingSound;
                     audio.Play();
                     playing$$anonymous$$oving = true;
                  }
                     
                     
  
        }
  
 }
                 Ah sorry, didn't notice this! Glad you've got it working...
Answer by berk_can · Aug 30, 2017 at 06:16 PM
For the people having different problem which causes no sound play
Go to Edit > Project Settings > Audio > (From Inspector) Uncheck Disable Unity Audio if Checked
Your answer
 
             Follow this Question
Related Questions
Audio is not playing but i don't have any compiler errors? 1 Answer
OneShot Audio not playing 1 Answer
A node in a childnode? 1 Answer
how do i make footsteps only sound when i move in the area i place the audio? 1 Answer
Animating an object so it doesn't bounce to the initial location the animation was recorded 1 Answer