static Music_Player instance = null; // our single music_player that the class will keep track of. //This music player will remain active throughout the entire game, or until we destroy it manually void Awake() { if (instance != null) // If there's no music player already existing { Destroy(gameObject); // Destroys the game object to which the current game object is attached } else { instance = this; // We set the instance var to the current musicplayer instance GameObject.DontDestroyOnLoad(gameObject); // gameObject is the literal game object that we've attached this script to, GameObject is the class of the method 'DontDestroyOnLoad' } }
private void Awake() { if (instance != null) { Destroy(gameObject); } else { instance = this; GameObject.DontDestroyOnLoad(gameObject); } }
// Use this for initialization void Start() { if (instance != null) { Destroy(gameObject); print("duplicate music player removed"); } else { instance = this; GameObject.DontDestroyOnLoad(gameObject); } }
void Awake() { if (instance != null) { Destroy(gameObject); print("Duplicate music player self-destructing"); } else { instance = this; GameObject.DontDestroyOnLoad(gameObject); } }
public void OnUnityAdsDidStart(string placementId) { adStarted = true; mPlayer = (Music_Player)FindObjectOfType(typeof(Music_Player)); if (mPlayer) { mPlayer.adAudioMute(); } else { Debug.Log("Couldn't find Music_player in scene"); } Time.timeScale = 0; }
void Awake() { //Debug.Log ("Testing Wake: "+ GetInstanceID()); // to prevent recreation of music, use the Singleton pattern, //which if there is no gameObject exists, set it; otherwise, destroy the new one. if (instence != null) { Destroy(gameObject); } else { instence = this; GameObject.DontDestroyOnLoad(gameObject); } }