/// <summary>This function returns the AudioSource that contains a specific sound /// <para>It has to be in the Sound asset referenced in the AudioManager instance</para> /// </summary> public AudioSource GetSource(string name) { Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound: " + name + " not found!"); return(null); } return(s.source); }
/// <summary>Use this to play one shot of a sound with a specific name /// <para>It has to be in the Sound asset referenced in the AudioManager instance</para> /// </summary> public void PlayOneShot(string name) { Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound: " + name + " not found!"); return; } s.source.pitch = s.RandomPitch; s.source.volume = s.RandomVolume; s.source.PlayOneShot(s.clip); }
IEnumerator FadeMutedOutCoroutine(string name, float fadeTime) { Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound: " + name + " not found!"); yield break; } while (s.source.volume > 0) { s.source.volume -= Time.deltaTime / fadeTime; yield return(null); } s.source.volume = 0; }
/// <summary>Use this to play an intro song and then start playing the song loop /// <para>It has to be in the Sound asset referenced in the AudioManager instance</para> /// </summary> public void PlayWithIntro(string intro, string song) { Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == intro); if (s == null) { Debug.LogWarning("Sound: " + intro + " not found!"); return; } s.source.pitch = s.RandomPitch; s.source.volume = s.RandomVolume; s.source.Play(); float introDuration = s.clip.length; Play(song, introDuration); }