Have some fun moment with music


Just to say that when we want to change music from menu to game but keep menu music in all menu brings some funy search in unity docs :smiley:
Maybe it’s aborded latter in course but, no matter, i’ve done that :

static MusicLoop instance = null;

// Use this for initialization
void Start () {
	if (instance != null && instance.name != this.name) {
		GameObject.Destroy (GameObject.Find(instance.name));
		Debug.Log ("changing music");
	} else if (instance != null) {
		GameObject.Destroy (gameObject);
		Debug.Log ("duplicate music");
	} else {
		instance = this;

		Debug.Log ("destroy game object");
		GameObject.DontDestroyOnLoad (gameObject);

I’ve put object on each scene, ‘MusicMenu’ for my menu scenes and MusicGame on my level_01 scene.
It may be not the better way do to but it works fine :smiley:

Privacy & Terms