public void PlaySound(AudioProps props, float vol = 1.0f) { if (isMute) { return; } props.vol = vol; // Look for a free audio source foreach (AudioSource source in audioSources) { if (source.isPlaying) { continue; } ApplyProperties(source, props); source.volume = props.vol; source.Play(); return; } // No free audio sources; create and use a new one AudioSource src = gameObject.AddComponent <AudioSource>(); ApplyProperties(src, props); src.volume = props.vol; src.Play(); audioSources.Add(src); }
public void PlaySound(AudioClip clip, float vol = 1.0f, float minPitch = 1.0f, float maxPitch = 1.0f) { AudioProps prop = new AudioProps(clip); prop.pitch = Random.Range(minPitch, maxPitch); PlaySound(prop, vol); }
public void PlaySound(string name, float vol = 1.0f) { if (soundLib.ContainsKey(name) == false) { Debug.Log("Sound library does not contain " + name + "."); } AudioProps props = GetAudio(name); PlaySound(props, vol); }
public void PlaySound(string name, float vol = 1.0f, float min = 1.0f, float max = 1.0f) { if (soundLib.ContainsKey(name) == false) { Debug.Log("Sound library does not contain " + name + "."); } AudioProps props = GetAudio(name); props.pitch = Random.Range(min, max); PlaySound(props, vol); }
void ApplyProperties(AudioSource src, AudioProps props) { src.clip = props.clip; src.pitch = props.pitch; }