Exemplo n.º 1
0
        //----------------------
        // Private Variables

        //----------------------
        // Protected Variables

        //========================================
        //      setter / getter
        //------------------------------

        //========================================
        //      Unity's function
        //------------------------------
        protected override void Awake()
        {
            base.Awake();

            // NOTE(jenchieh): Only the first time will call this.
            // This game object is a unique game object. Meaning the
            // object itself uses 'DontDestroyOnLoad' function.
            if (instance == null)
            {
                instance = this;

                // ==> OnLevelWasLoaded <==
                UnityEngine.SceneManagement.SceneManager.sceneLoaded += (scene, loadingMode) =>
                {
                    // set to Sound Manager in order to get manage
                    JCS_SoundManager.instance.SetBackgroundMusic(GetAudioSource());

                    if (!JCS_SoundSettings.instance.KEEP_BGM_SWITCH_SCENE)
                    {
                        // Assign BGM from Sound Manager!
                        GetAudioSource().clip = JCS_SoundSettings.instance.BACKGROUND_MUSIC;

                        GetAudioSource().Play();
                    }
                };
            }
            else
            {
                if (instance != this)
                {
                    Destroy(this.gameObject);
                }
            }
        }
Exemplo n.º 2
0
        protected override void Awake()
        {
            base.Awake();

            // NOTE(jenchieh): Only the first time will call this.
            // This game object is a unique game object. Meaning the
            // object itself uses 'DontDestroyOnLoad' function.
            if (instance == null)
            {
                instance = this;

#if UNITY_5_4_OR_NEWER
                // ==> OnLevelWasLoaded <==
                SceneManager.sceneLoaded += (scene, loadingMode) =>
                {
                    LevelLoaded();
                };
#endif
            }
            else
            {
                if (instance != this)
                {
                    Destroy(this.gameObject);
                }
            }
        }