- Home /
Question by
fogsam · Jan 26, 2012 at 12:43 PM ·
javascriptaudioaudiosource
background Audio plays in Unity Editor but does not play in web player
Hey Guys
I have a car game, and all of the engine sounds are working in the editor and compiled web player. But as soon as i add in the background music it stops working in the Complied Web Player version.
here is the code:
var BackgroundMusic : AudioClip = null;
var BackgroundMusicVolume : float = 0.6;
private var backgroundMusic : AudioSource = null;
function Start () {
backgroundMusic = gameObject.AddComponent(AudioSource);
backgroundMusic.loop = true;
backgroundMusic.playOnAwake = true;
backgroundMusic.clip = BackgroundMusic;
// backgroundMusic.maxVolume = BackgroundMusicVolume;
// backgroundMusic.minVolume = BackgroundMusicVolume;
backgroundMusic.volume = BackgroundMusicVolume;
}
Any help will be greatly appreciated.
thanks
Comment
Answer by fogsam · Jan 27, 2012 at 10:45 AM
Ill answer this myself.
Rather than add the music via code i just dragged the audio clip into the game, creating a 2D Audio Source game object and i just clicked the play on awake and loop. I feel a little silly really :P
Your answer
![](https://koobas.hobune.stream/wayback/20220613063421im_/https://answers.unity.com/themes/thub/images/avi.jpg)