void Start() { GameObject music = GameObject.FindGameObjectWithTag("Music"); if (music != null) { musicPlayer mp = music.GetComponent <musicPlayer>(); mp.PlayMusic(); } }
// Use this for initialization void Awake() { // If we haven't had a music player before, create a musicPlayer and assign the instance to it. otherwise, destroy this if (musicPlayer.instance != null) { Debug.Log ("Destroying duplicate musicPlayer"); Destroy (gameObject); } else { musicPlayer.instance = this; GameObject.DontDestroyOnLoad (gameObject); } }
void Awake() { if (instance != null) { Destroy(gameObject); } else { instance = this; GameObject.DontDestroyOnLoad(gameObject); } }
// Use this for initialization void Start() { if (instance == null) { instance = new musicPlayer(); GameObject.DontDestroyOnLoad(instance); } else { Destroy(instance); } }
void Awake() { if (instance != null) { Destroy(gameObject); print("duplicate musicPlayer destroyed"); } else { instance = this; GameObject.DontDestroyOnLoad(gameObject); } }
void Awake() { if (instance != null && instance != this) { Destroy(gameObject); return; } else { instance = this; } DontDestroyOnLoad(gameObject); }
void Awake() { DontDestroyOnLoad(this); _audioSource = GetComponent <AudioSource>(); if (musicPlayerInstace == null) { musicPlayerInstace = this; } else { DestroyObject(gameObject); } }
void Awake() //put int awake will make music flow stimutaneously { Debug.Log("Music player Awake " + GetInstanceID()); if (instance != null) //prevent new musicplayer is created(If another scene has music player or move back to start menu) { Destroy(gameObject); Debug.Log("Duplicate music player self-destructing!"); //make new music get destroy before run start } else { instance = this; GameObject.DontDestroyOnLoad(gameObject); Debug.Log("Music created!!!"); } }
void Awake() { //if we don't have an [_instance] set yet if (!_instance) { _instance = this; } //otherwise, if we do, kill this thing else { Destroy(this.gameObject); } DontDestroyOnLoad(this.gameObject); }
// Use this for initialization void Start() { if (instance != null && instance != this) { Destroy(gameObject); print("Duplicate music player self-destructing"); } else { instance = this; GameObject.DontDestroyOnLoad(gameObject); music = GetComponent <AudioSource>(); music.clip = startClip; music.loop = true; music.Play(); } }