[SOLVED] Why does my music get killed straight away?

I’ve just watched and carried out the work on the BlockBreaker scrip to make the music play once at the beginning…
I’ve checked that my code is the same as the screen grabs etc.

HOWEVER - the music is stopped after the first ‘blip’ of the tune.
The menu cycles through correctly, the log counts up - indeed showing that the music is killed straight away…
WHY??

using UnityEngine;
using System.Collections;

public class MusicPlayer : MonoBehaviour {
static MusicPlayer instance = null;

// Use this for initialization
void Start () {
	if (instance != null) {
		Destroy (gameObject);
		print ("Duplicate music player self-destructing");
	} else {
			instance = this;
			GameObject.DontDestroyOnLoad(gameObject);			
		}

}

// Update is called once per frame
void Update () {

}

}

I forgot to add that it DID WORK (as in it created multiple versions of the MusicPlayer) when you cycled through the system…

Your code looks fine (although you could change the Start event to the Awake event), so I’m guessing the problem lies elsewhere. Can you post a screenshot of the MusicPlayer inspector?

1 Like

Hey,
Thanks for replying - You did manage to make me find the solution myself.
In asking for a screenshot of the MusicPlayerInspector I discovered I had (SOMEHOW) got TWO Music Player Scripts in there…
Deleted one and PROBLEM SOLVED - THANK YOU, Nerrickk

Duck debugging at it’s best! :smiley:

Privacy & Terms