示例#1
0
        public static void PlaySFX(SFXClip sfx, bool waitForFinish = true, AudioSource audioSource = null)
        {
            #region Set Audio Source
            if (!audioSource)
            {
                audioSource = SFXManager.instance.defaultAudioSource;
            }

            if (!audioSource)
            {
                Debug.LogError("You forgot to add a default audio source!");
                return;
            }
            #endregion

            if (!audioSource.isPlaying || !waitForFinish)
            {
                var clip = sfx.GetClip();

                audioSource.clip   = clip;
                audioSource.volume = sfx.volume + Random.Range(-sfx.volumeVariation, sfx.volumeVariation);
                audioSource.pitch  = sfx.pitch + Random.Range(-sfx.pitchVariation, sfx.pitchVariation);
                audioSource.Play();
            }
        }
示例#2
0
        private void SFXChange()
        {
            //keep the label up to date
            sfxLabel = sfxType.ToString() + " SFX";

            //keep the displayed "SFX clip" up to date;
            _sfxBase = sfxToPlay;
        }