- Home /
The question is answered, right answer was accepted
Audio Issue
Greetings, I am trying to get it so that when a counter variable reaches a certain number, that a sound plays on a loop. This, however, is not the issue. I cannot get the sound to play, even though it plays loud and clear in the inspector window. After messing around with the settings to no avail, I eventually stumbled upon something strange. The only way that I can get the audio to play is if I run the scene in the Unity Editor (or in a build, doesn't matter), then alt-tab out of it. The sound plays as normal, yet when I alt-tab back into Unity, the sound stops abruptly. If more detail is necessary to give a proper assessment, just ask ;) Has anyone else had a similar issue? If so, how have you solved it?
Edit: I have played around with it a bit more. I have a timer on the HUD, and when the timer isn't counting up (paused, hence the alt-tab), the audio plays.
tl;dr: Only when the game is paused will the audio play, which is exactly opposite as to what I need.
Answer by Blasfemmy · Jan 16, 2013 at 11:49 PM
SOLVED:
I had an infinite loop of playing the audio when the game was running. Here is the working script:
 #pragma strict
 
 @script RequireComponent( AudioSource )
 
  
 
 var papers : CollectPapers;
 
  
 
 var num : float = 0.0;
 
  
 
 var ambiance : AudioSource;
 
  
 
 var hasplayed : boolean = false;
 
  
 
 function Start () {
 
     audio.priority = 0;
 
 }   
 
  
 
 function Update () {
 
     if ( papers.papers >= num )
 
     {
 
         if(hasplayed){} 
 
             else
 
             {
 
                 audio.Play();
 
                 hasplayed=true;
 
  
 
             }
 
     }
 
 }
Follow this Question
Related Questions
Problem with Footstep System 1 Answer
AudioSource.Pause not working? 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                