- Home /
Question by
JimmyNijs1988 · Jul 14, 2020 at 10:49 AM ·
androidbuildaudiomusic
Music between scenes. Works in editor not after building for androit?
I used the audiomanager from Brackeys as a basis. I want the music to continu on between different scenes. And in the editor thats working perfectly. When i build the app and play it (androit) however the music gets cut off when i change scenes. It restarts again.. Please help!
using UnityEngine.Audio; using System; using UnityEngine;
public class AudioManager : MonoBehaviour { public static AudioManager instance; public AudioMixerGroup mixerGroup; public Sound[] sounds;
void Awake()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
}
{
s.source = gameObject.AddComponent<AudioSource>();
s.source.clip = s.clip;
s.source.loop = s.loop;
s.source.outputAudioMixerGroup = mixerGroup;
}
}
public void Play(string sound)
{
Sound s = Array.Find(sounds, item => item.name == sound);
if (s == null)
{
Debug.LogWarning("Sound: " + name + " not found!");
return;
}
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
s.source.Play();
}
public void Stop(string sound)
{
Sound s = Array.Find(sounds, item => item.name == sound);
if (s == null)
{
Debug.LogWarning("Sound: " + name + " not found!");
return;
}
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
s.source.Stop();
}
}
Comment