I have script that will start a Music playing but realised that sometimes they are not stopped and continue playing after i loaded a new script.
This resulted in multiple Music playing. Is there another way that can help to shut down the Music before the next script is loaded?
backgroundSoundInstance = backgroundSoundCurrent.Result.LoadSoundByMode( mode );
if( backgroundSoundInstance != null )
{
var group = SoundWorld.GetChannelGroup( "Music" );
if( group == null )
group = EngineApp.DefaultSoundChannelGroup;
backgroundSoundChannel = SoundWorld.SoundPlay( null, backgroundSoundInstance, group, 1, true );
}
` public static void StopMusic( UIContainer obj )
{
if( backgroundSoundChannel != null )
backgroundSoundChannel?.Stop();
backgroundSoundChannel = null;
backgroundSoundInstance = null;
backgroundSoundCurrent = null;
}`