- Home /
Menu Music Issue!!
Hello, I'm using DontDestroyOnLoad to play music through various menu scenes, the code looks like :
function Awake() {
// see if we've got game music still playing
var gameMusic : GameObject = GameObject.Find("GameMusic");
if (gameMusic) {
// kill game music
Destroy(gameMusic);
}
// make sure we survive going to different scenes
DontDestroyOnLoad(gameObject);
}
function Awake() {
// see if we've got menu music still playing
var menuMusic : GameObject = GameObject.Find("MenuMusic");
if (menuMusic) {
// kill menu music
Destroy(menuMusic);
}
// make sure we survive going to different scenes
DontDestroyOnLoad(gameObject);
}
since I have used play on awake, the music starts from beginning whenever I move back from submenu's to the main menu...Then I will have two music playing at the same time... Is there any way I could stop this from happening?
Why do you have more than one scene to manage your main menu?
Also having two awake functions isn't great as there isn't an overloading happening, which one is being called?
Why not add Debug.Log to each awake and see what is happening, that way you can track your code better :D
Answer by ramp · Jan 09, 2015 at 12:34 PM
Hello,
Create an empty game object in first menu scene with tag name music and add audio source component to the GameObject playing your music automatically and then use the following code,may be help.
void Awake ()
{
if (GameObject.FindGameObjectsWithTag ("music").Length > 1)
Destroy (this.gameObject);
DontDestroyOnLoad(gameObject);
}
Thanks
Ram
Your answer
Follow this Question
Related Questions
Music track selector 1 Answer
Play again music problem. (Please help) :) 0 Answers
How to stop menu music when loading level (1,2,3,..,x) 1 Answer
How do I make music continue through certain scenes 1 Answer
How do I make a menu with a video in the background? And how do I put music on it? 0 Answers