- Home /
Music multiple scenes - Bug or really simple error?
Hey everyone,
I have built a game that Has a Main Menu and a Music credit page (accessable fromt Main Menu through GUI button.
I have music on a empty GameObject and in my GUI button script looks like this;
if (GUI.Button (Rect ( Screen.width * 0.75, Screen.height * 0.4, 120, 50), "Music", "button")) {
DontDestroyOnLoad(GameObject.Find("musicplayer"));
Application.LoadLevel ("musicpage");
}
So the new page loads fine, the GameObject is there, BUT no music is playing?.... why?
...i just found now, when i return to the main menu from the $$anonymous$$usic page, the song continues from where it left off?... so why cant i hear it in the music page?
..also i have just realised a fault with my logic.. because i had a dontdestroy on my music music page returning back to the main menu, the song resume there (as per above?) but also a new instance would begin to play.. crap! the singleton maybe be my best option :(
Answer by Matthew 5 · Feb 07, 2011 at 03:51 AM
Just to bring closure to this post.. i created a blank scene at the start of my project with AudioSource, AudioListener & DontDestroyOnLoad.
Then in the "Intro/Menu" scene i had a script which check ifaudio is playing, dont destroy, if not, play new instance... then the DestroyObject was in my first level of the game.... worked a treat.
Answer by Bunny83 · Jan 28, 2011 at 03:42 AM
When your "musicplayer" still exists in your "Music page" i guess you don't have an AudioListener in your scene. The Listener is normally attached to your camera.
You may also take a look at the scripting reference.
This was exactly the reason why it didnt work AND got me to figured out the rest of the problem. Thank you