Beispiel #1
0
        public void PlaySoundEffect(SoundEffectNames effect)
        {
            SoundEffectInstance soundEffectInstance = this.sfxList[effect].CreateInstance();

            if (this.isMute)
            {
                soundEffectInstance.Volume = 0;
            }
            soundEffectInstance.Play();
            this.soundInstances.Add(soundEffectInstance);
        }
Beispiel #2
0
 public void PlaySoundEffect(SoundEffectNames soundEffectName)
 {
     for (int i = 0; i < soundEffects.Length; i++)
     {
         if (soundEffects[i].Name == soundEffectName)
         {
             soundEffects[i].Source.clip   = soundEffects[i].Clips[UnityEngine.Random.Range(0, soundEffects[i].Clips.Length)];
             soundEffects[i].Source.volume = soundEffects[i].Volume;
             soundEffects[i].Source.Play();
             return;
         }
     }
     Debug.Log("Sound effect not found!");
 }
Beispiel #3
0
    /*
     * When a sound effect is played the enum name for it is passed in
     * This is used in a for loop to find it from the list of SFXs available
     * A SFX prefab (AudioSource) is then spawned and its clip is set to the correct clip
     * The clip is then played and the prefab is destroyed once the clip has finished
     */
    public void PlayEffect(SoundEffectNames name)
    {
        for (int i = 0; i < soundEffects.Length + 1; i++)
        {
            if (soundEffects[i].name == name)
            {
                GameObject  currentSFX = Instantiate(SFXPrefab);
                AudioSource currentAS  = currentSFX.GetComponent <AudioSource>();

                currentAS.clip = soundEffects[i].clip;
                currentAS.Play();

                Destroy(currentSFX, currentAS.clip.length);

                break;
            }
        }
    }
 public void PlaySoundEffect(SoundEffectNames soundEffectName)
 {
     audioSource.PlayOneShot(SoundEffects[soundEffectName]);
 }