Hey I was wondering if there is a way to have the same clip play nonstop throughout the options and start menu. I’d like the same song to play without being restarted. If someone could help out thatd be awesome!
public AudioClip[] levelMusicChangeArray;
private AudioSource audioSource;
void Awake()
{
DontDestroyOnLoad(gameObject);
Debug.Log("Don't destroy on load" + name);
audioSource = GetComponent<AudioSource>();
}
void OnLevelWasLoaded(int level)
{
AudioClip nowPlaying = levelMusicChangeArray[level];
Debug.Log("Playing clip: " + levelMusicChangeArray[level]);
// If there is some music attached.
if (nowPlaying)
{
audioSource.clip = nowPlaying;
audioSource.loop = true;
audioSource.Play();
}
}