/* Functions */

        /// <summary>
        /// When is on destroy play the sound.
        /// </summary>
        private void OnDestroy()
        {
            // if is quitting the application don't spawn object,
            // or else will cause memory leak!
            if (JCS_ApplicationManager.APP_QUITTING)
            {
                return;
            }

            // if switching the scene, don't spawn new gameObject.
            if (JCS_SceneManager.instance.IsSwitchingScene())
            {
                return;
            }

            // create object to do the event
            GameObject obj = new GameObject();

            // this object will play the sound, after the sound is played.
            // will destroy it self automatically.
            JCS_DestroySoundEndEvent dsee = obj.AddComponent <JCS_DestroySoundEndEvent>();

#if (UNITY_EDITOR)
            obj.name = "JCS_OnDestroyPlaySoundEvent";
#endif
            dsee.SetAudioClipAndPlayOneShot(mAudioClip, mSoundSettingType);
        }
예제 #2
0
        private void OnDestroy()
        {
            // if is quitting the application don't spawn object,
            // or else will cause memory leak!
            if (JCS_ApplicationManager.APP_QUITTING)
            {
                return;
            }

            // if switching the scene, don't spawn new gameObject.
            if (JCS_SceneManager.instance.IsSwitchingScene())
            {
                return;
            }

            if (!mActiveWithHitList)
            {
                if (mHitList.IsHit)
                {
                    return;
                }
            }

            if (!mActiveWithDestroyTime)
            {
                if (mDestroyObjectWithTime != null)
                {
                    if (mDestroyObjectWithTime.TimesUp)
                    {
                        return;
                    }
                }
            }

            // Add Destroy Sound
            GameObject gm = new GameObject();
            JCS_DestroySoundEndEvent dse = gm.AddComponent <JCS_DestroySoundEndEvent>();

#if (UNITY_EDITOR)
            gm.name = "JCS_DestroySoundEffect";
#endif
            AudioClip ac = this.mRandomSoundAction.GetRandomSound();
            if (ac != null)
            {
                dse.SetAudioClipAndPlayOneShot(ac, mRandomSoundAction.SoundType);
            }
        }
        /* Functions */

        private void Start()
        {
            GameObject obj = new GameObject();
            JCS_DestroySoundEndEvent dsee = obj.AddComponent <JCS_DestroySoundEndEvent>();

#if (UNITY_EDITOR)
            obj.name = "JCS_SoundProxyAction";
#endif

            if (mAudioClip == null)
            {
                JCS_Debug.LogError(
                    "You called a proxy action but without data in it...");
                return;
            }

            dsee.SetAudioClipAndPlayOneShot(mAudioClip, mSoundSettingType);
        }