continuous music that stops on some scenes
so I have an issue in one of my games. I have found a way so that I can have music that continues over scenes without it stacking or anything. The issue that I have with this is that if I change to a different scene where I want different music to play, it just destroys that game object in that scene, and continues playing the same menu music from before.
please help.
Script:
using UnityEngine; using System.Collections;
public class music : MonoBehaviour {
void Start(){
DontDestroyOnLoad (gameObject);
if (Application.loadedLevel == 1) {
Destroy (this.gameObject);
}
}
}
When it loads number 1 scene, I want it to stop playing the current music and use the music game object on that scene.
`
Why not just make one audio object persist across scenes, then just change the clip it plays for each scene?
Ive tried this, but it just destroys the new game object, and keeps playing the same song as before. Essentially for every scene it will just play the same song even if I tell it to change.
Ive also tried using the "OnLevelWasLoaded", but that just doesn't seem to work for me either.
I feel like this whole process has a solution that is much easier than what Im doing, Im just overlooking it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612054805im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I have a life added bar every time I reach 5000 points 0 Answers
Unity2D Door and Button Pairing,Unity2D door and button pairing 0 Answers
How to I make there only be a chance to be sold every 2 seconds. 0 Answers
Which music goes? 0 Answers
Unity Parsing Error CS8025 on Last Line? 2 Answers