Created
December 30, 2018 17:24
-
-
Save kojinkai/4cf6dfdaf1dc96cca1cd428df12642f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class SoundTrackController : MonoBehaviour | |
{ | |
private void Awake() | |
{ | |
// We want this soundTrackController to persist across every scene (singleton) | |
// so we check if there is an existing instance and reuse that, destroying the attempted new | |
// instance in the process. | |
// GetType returns the type of the current gameobject the script is attached to | |
if (FindObjectsOfType(GetType()).Length > 1) | |
{ | |
gameObject.SetActive(false); | |
Destroy(gameObject); | |
} | |
else | |
{ | |
DontDestroyOnLoad(gameObject); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment