- Home /
How to stop menu music when loading level (1,2,3,..,x)
Hello!
I managed to find a way to have a menu song that doesn't start over between different menu scenes, but I'd like it to stop when I load a playable level. The menu music just seems to turn to a REALLY low volume, but it is still audible.
These two scripts are taking care of the menu music. Could you please find a solution for me?
public class MyUnitySingleton : MonoBehaviour {
private static MyUnitySingleton instance = null;
public static MyUnitySingleton Instance {
get { return instance; }
}
void Awake() {
if (instance != null && instance != this) {
Destroy(this.gameObject);
return;
} else {
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}
}
.
public class MusicManager : MonoBehaviour {
public AudioClip NewMusic; //Pick an audio track to play.
public GameObject go;
void Awake () {
go = GameObject.Find("Game Music");
//Finds the game object called Game Music, if it goes by a different name, change this. go.audio.clip = NewMusic;
//Replaces the old audio with the new one set in the inspector. go.audio.Play();
//Plays the audio.
}
}
Why are you finding the gameobject with the game music on awake ins$$anonymous$$d of directly affiliating it with the script through the editor?
Also, if it goes quiet, make sure the music being played has "3D sound" disabled. This means that the music will be played at constant volume regardless of its distance to the audio listener.
I created a "$$anonymous$$enu $$anonymous$$usic" gameObject in each scene that I want the music to be played. Should I do it the other way?
Answer by alok-kr-029 · Feb 19, 2015 at 12:39 PM
try this AudioSource Audio1 = GameObject.Find("YourgameObject name ").getComponent().Stop();
AudioSource Audio1 = GameObject.Find ("YourgameObject name ").GetComponent<AudioSource> ().volume = 0;
or
AudioSource Audio1 = GameObject.Find ("YourgameObject name ").GetComponent <AudioSource>.Stop() ;
Try this
Your answer
Follow this Question
Related Questions
Play again music problem. (Please help) :) 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Pause Menu Not Pausing 3 Answers