- Home /
Playing the same song on different scenes
Hi there,
I have a simple question,
In my game, I have a scene to choose map, a scene to look at the score, a scene for the credit and so on. I would like to loop a song ( ok for this ) for those scene ( the same song for each scene ). The thing is everytime I change scene, the song restarts.
How can I make this song play whatever of those scene im in ?
You'll need to use DontDestroyOnLoad :
http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
however, if you do this at the main menu, then from the end of the game co$$anonymous$$g back to the main menu, a new player will be created, so you have to check that if there is an object already existing (because of DontDestroyOnLoad), then destroy itself. Did that make sense? Because the object is not destroyed, every time you enter the scene that has the object, another will be created, but you only want one in existance. (That wasn't much better, was it :S )
I'll look into making a script for this, unless one of the pro's submits an answer for you =]
when I did this, I found using a Singleton helped in making sure only one 'music player' was in existance.
actually, the first link on Seth's answer is probably the best example using a singleton method (upvote for you sir) =]
http://answers.unity3d.com/questions/11314/audio-or-music-to-continue-playing-between-scene-c.html
Answer by Seth-Bergman · Jul 25, 2012 at 03:06 PM
http://answers.unity3d.com/questions/11314/audio-or-music-to-continue-playing-between-scene-c.html
http://answers.unity3d.com/questions/59135/playing-music-while-scenes-change.html
http://answers.unity3d.com/questions/11671/play-music-through-multiple-scenes.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613074701im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to know the time of the song? 1 Answer
Music does not play between scenes 2 Answers
The simple way to put sounds in a game? 1 Answer
Can not play a disabled audio source persistent problem 0 Answers
ReverbZone affects 2D sounds 1 Answer