I’m currently using Audio.Listener.pause = true; to pause sound in my game and false to restart play.
My question is, how can I use the above in conjunction with a fade out? My music source is located in the first scene, and using script, continues across all scenes until paused.
I’ve tried other fade code I’ve found in Unity, but everything so far crashes the app.
The easiest way to do it is to start a coroutine that lowers the volume of the AudioSource by some fade increment, yields for a small amount of time, and then repeats in a loop until the volume == 0. If you’re loading multiple scenes while fading, though, you’d want to delay the Application load operation until the fade completed in a single scene. I didn’t really understand the pause thing you mentioned; if you’re fading, you don’t want the audio paused.
Another way to do it is to have a native player from the Objective-C side handle audio playback, and communicate with it through PlayerPrefs on the Unity side and NSUserDefaults on the Objective-C side – this would give you better audio performance (and streaming) and allow you to fade natively regardless of scene loading in Unity.
i had tried incrementing the audio volume, but when I did the app kept crashing — no idea why ><
Also, if I only want to fade ONE audio source (e.g. music), whilst all other sources remained at maximum volume, is it as simple as just defining that source and fading that alone or does audio volume apply to ALL audio?
Thanks — I’ve been searching the net on how to use a native player from Obj-C but can’t find any information. Do you know where I could look? Note that I’m not a ‘real programmer’