- Home /
Music on multiple scenes
function Awake()
{ var gameMusic : GameObject = GameObject.Find("GameMusic");
DontDestroyOnLoad(gameObject);
if (gameMusic) { Destroy(gameMusic); }
}
This script allows the background music to play through the different scenes, but when I get back to the main menu page, the music starts all over again, overlapping the one which is continuing from before. How do I stop this from happening?
Thank you.
Answer by AliAzin · Sep 06, 2010 at 10:10 AM
try putting your music player on a level before your main menu page.
Answer by Niklas · Mar 18, 2011 at 04:30 PM
Another more robust way would be to make the sound player singleton. Seems like you are doing it backwards and destroys the old object and allows the new one to be created. Some pseudo code:
void Start() { // Find GameObjects of same type // if num > 0 // Destroy this.gameObject // Return
// Do normal stuff }
Your answer
Follow this Question
Related Questions
Sound stops when object is destroyed 6 Answers
Play sound on button click before loading level. 3 Answers
5.1 Channels is backwards in unity (non 3D) 0 Answers
How to loop a sound clip on a ButtonDown function 1 Answer
Need help making an audio trigger. 2 Answers