Hey everyone, I’m trying to get the audio set up for our main menu. I created an empty game object and made it persistent so it doesn’t stop playing whenever you switch screens. It play’s all the way up until you start the race and then I destroy it. Now from what I’ve gathered for unity whenever I go back to the main menu there should be a new one in it’s place because that’s how I saved the level. And it’s there, but the problem is the music never starts back up. I’ve tried to start it manually in the start() function using audio.play but that didn’t work either. Does anyone know what’s going on with this? Here’s the code I was trying to use.
function Start () {
po = GameObject.Find(“PersistentOBJ”).GetComponent(PersistentController);
DontDestroyOnLoad(GameObject.Find(“MusicHolder”));
GameObject.Find(“MusicHolder”).GetComponent(AudioSource).audio.Play();
}
I get what you’re telling me to do, but I think this is what I was trying to do in the first place and it ends up causing the same error. Just let me make sure we’re both on the same page here though. I think you’re saying just to mute the music object whenever the game loads a stage and unmute it when it returns to the menu. The only problem with that is I still have to destroy the object before it goes back to the menu or else there will be multiple instances of the music holder. And destroying the music object seems to be whats causing the issue. Am I right?
I do not really think you have to destroy the object. Or else, just attach audio listener to the main camera in Main Menu and attach a script like that to the main camera Then it should not be any multiple instances.