private IEnumerator PlayOneShotSoundAtCoroutine(SoundNames name, AudioSource audioSource, float delay) { if (delay > 0) { yield return(new WaitForSeconds(delay)); } CorrectedSoundClip clip = null; float minPitch = 0; float maxPitch = 0; for (int i = 0; i < sounds.Length; i++) { Sound sound = sounds[i]; if (sounds[i].name == name) { clip = sound.audioClips[UnityEngine.Random.Range(0, sound.audioClips.Length)]; minPitch = sound.minPitch; maxPitch = sound.maxPitch; } } if (clip == null) { Debug.LogError("NO SOUND FOUND!"); } else { audioSource.clip = clip.clip; audioSource.pitch = UnityEngine.Random.Range(minPitch, maxPitch); audioSource.volume = clip.volume; audioSource.Play(); } }
private IEnumerator PlayOneShotSoundAtCoroutine(SoundNames name, Vector3 position, float delay) { if (delay > 0) { yield return(new WaitForSeconds(delay)); } CorrectedSoundClip clip = null; float minPitch = 0; float maxPitch = 0; float volumeModification = 0; for (int i = 0; i < sounds.Length; i++) { Sound sound = sounds[i]; if (sounds[i].name == name) { int clipIndex = 0; for (int j = 0; j < 8; j++) { clipIndex = UnityEngine.Random.Range(0, sound.audioClips.Length); if (!sound.audioClips[clipIndex].ignoreMe) { break; } } clip = sound.audioClips[clipIndex]; minPitch = sound.minPitch; maxPitch = sound.maxPitch; volumeModification = UnityEngine.Random.Range(0, sound.volumeModifier); } } if (clip == null) { Debug.LogError("NO SOUND FOUND: " + name.ToString()); } else { AudioSource oneShotSound = GetAvailableAudioSource(); oneShotSound.transform.position = position; oneShotSound.clip = clip.clip; oneShotSound.pitch = UnityEngine.Random.Range(minPitch, maxPitch); oneShotSound.volume = clip.volume + volumeModification; oneShotSound.Play(); } }