Hi guys.
I'm struggling to get my music background to work. I have an emty gameobject with AudioSource attached, a 2D sound was dragged to the Audio Clip slot, a script like this was also attached to the gameobject:
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
function Start ()
{
audio.Play();
audio.loop = true;
}
1st tried method. It works fine through all the scenes. There wasn't any "double sound" issue because i make the gameobject static. The only problem is that when i turn on/off the sound (audio.Pause()), the sound continues to play because Start function only gets called once in the lifetime of the behavior. Because of that, i used Update but the sound plays very laggy. What function should i use?
2nd tried method. I know that we can also pause the AudioListener, but when i minimize my game down the taskbar and later restore its window back, the sound plays for 1 or 2 seconds right before the scene is loaded even when the audio listener is in Pause mode. This can be very annoying :( How do i fix this?
The script attached to main camera:
function Update () {
if (!gamemusicmanager.musicon)
{
AudioListener.pause = true;
}
else
{
AudioListener.pause = false;
}
}
Can i have some suggestions from you guys?
Thanks!!
I think you're looking at it the wrong way. The music starts on the Awake function and the update function just checks whether or not your pausing it or not, use ""Time.timeScale = 0.0;"" to pause the music.
– anon61858128