Advertisement
Guest User

MusicPlayer

a guest
Oct 2nd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class MusicPlayer : MonoBehaviour
  7. {
  8. static MusicPlayer instance = null;
  9.  
  10. void Awake ()
  11. {
  12. if (instance != null)
  13. {
  14. Destroy (gameObject);
  15. }
  16. else
  17. {
  18. instance = this;
  19. GameObject.DontDestroyOnLoad (gameObject);
  20. }
  21. }
  22.  
  23. void Update ()
  24. {
  25. Scene currentScene = SceneManager.GetActiveScene ();
  26. string sceneName = currentScene.name;
  27.  
  28. if (sceneName == "GameOver" || sceneName == "Win")
  29. {
  30. Destroy (this.gameObject);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement