Пример #1
0
 void Awake()
 {
     if(!_instance){
         GameObject.DontDestroyOnLoad(gameObject);
         _instance = this;
         AudioListener.volume = PlayerPrefs.GetFloat("sound", 0.5f);
     }else{
         Destroy(gameObject);
     }
 }
Пример #2
0
    // Create a static instance.
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;

            // Make sure this object isn't destroyed when a new scene is loaded.
            DontDestroyOnLoad(this.gameObject);

            // Play the music.
            OnLevelWasLoaded(0);
        }
        else
        {
            // Play the music.
            Instance.Play(this.clip);

            DestroyImmediate(gameObject);
        }
    }