|
Hi guys, I have been stuck on reaching an effective method for creating an instance of game music in the main menu and in the levels. What I hope to achieve is one piece of music playing through the different menu scenes and then another piece of music for the game. The problem I have is when using 'DontDestroyOnLoad' I get music spawning twice! Any help on how to make a music manager script would be very much appreciated thank you.
(comments are locked)
|
|
The problem is that the music playing object exists in the scene to begin with, so when the scene is loaded again, a new instance is loaded as well. Since you can't undo I personally use this script here to manage all those objects, and tag them "DontDestroy". This script also manages applying the This is perfect! Thank you so much you have saved me so much hassle!
May 03 '12 at 01:03 PM
buxton4life
Asafsitner, the script works fine with not destroying or duplicating the music. But how would I switch the music from the menu music to the game music? Sorry for the complication.
May 03 '12 at 02:53 PM
buxton4life
Are you using the same object to play both music tracks?
May 03 '12 at 09:40 PM
asafsitner
Yes I am..is that wrong :/ I simply have a gameObject named "gameMusic" in both MainMenu and Level1. Both have the same script HouseKeeping and both tagged DontDestroy, the only difference is the music track applied in the inspector. Hope you can visualise that :) Any help would be awesome. Thanks again.
May 03 '12 at 09:52 PM
buxton4life
(comments are locked)
|
|
You can use the singleton pattern. There is a lot of forum posts and questions in Unity Answers regarding this topic. For example: http://answers.unity3d.com/questions/17916/singletons-with-coroutines.html Thanks Nicolas for the reply I will certainly look into it.
May 03 '12 at 01:04 PM
buxton4life
(comments are locked)
|
