Hello hero, so I am beginner, and basically what i want to do is, Whenever I switch scenes while playing, I have this button Esc. as pauses the game and loads u to a screen where it has paused.... the problem is I can't stop the music already playing at the beginning of the start, where it keep on playing and when i press Esc. i get to the paused scene, but the old music is still playing with the other music which is really annoying, Here is the code below.
The errors i get are 2, first is error CS0019: Operator `!=' cannot be applied to operands of type `MusicPlayer' and `string'
second is error CS0428: Cannot convert method group `DestroyObject' to non-delegate type `MusicPlayer'. Consider using parentheses to invoke the method
using UnityEngine;
using System.Collections;
public class MusicPlayer : MonoBehaviour {
static MusicPlayer instance = null;
void Awake () {
Debug.Log("Music player Awake" + GetInstanceID());
if (instance != null) {
Destroy (gameObject);
print ("Duplicate Music player self-destructing!");
}
else if (instance != ("Level_01") || instance != ("Level_02")) {
instance = DestroyObject;
}
else {
instance = this;
GameObject.DontDestroyOnLoad(gameObject);
}
}
}
↧