// SOUNDS public void PlaySound(SoundNames soundID) { SoundSO sound = Sounds.Find(s => s.SoundID == soundID); if (sound != null) { StartCoroutine(PlayingSound(sound)); } }
private SoundSO GetSound(SoundSO sound) { if (!soundsList.Contains(sound)) { soundsList.Add(sound); sound.source = gameObject.AddComponent <AudioSource>(); sound.Init(); } return(sound); }
private SoundSO GetSound(string name) { SoundSO s = Array.Find <SoundSO>(sounds, sound => sound._name == name); if (s.source == null) { s.source = gameObject.AddComponent <AudioSource>(); s.Init(); } return(s); }
public void PlaySound(string soundName) { SoundSO s = Array.Find(sounds, sound => sound.name == soundName); if (s == null) { Debug.LogWarning("Sound: " + soundName + " not found"); return; } if (!s.multipleSounds) { s.source.Play(); } else { s.source.clip = s.clips[UnityEngine.Random.Range(0, s.clips.Length - 1)]; s.source.Play(); } }
public IEnumerator PlayingSound(SoundSO sound) { AudioSource audio = Instantiate(Resources.Load("Prefabs/AudioPrefab") as GameObject, SoundsContainer.transform).GetComponent <AudioSource>(); if (!SoundSources.ContainsKey(sound.SoundID)) { SoundSources.Add(sound.SoundID, new List <AudioSource>()); } SoundSources[sound.SoundID].Add(audio); audio.PlayOneShot(sound.Sound); yield return(new WaitForSeconds(sound.Sound.length)); SoundSources[sound.SoundID].Remove(audio); if (SoundSources[sound.SoundID].Count <= 0) { SoundSources.Remove(sound.SoundID); } Destroy(audio.gameObject); }
public void PlayAudio(SoundSO soundToPlay) { SoundSO soundSelected = Array.Find(sound, sound => sound.name == soundToPlay.name); soundSelected.source.Play(); }
public void SetVolume(SoundSO sound, float volume) { GetSound(sound).SetVolume(volume); }
public void StopPlay(SoundSO sound) { GetSound(sound).Stop(); }
public void PlaySoundEffect(SoundSO sound) { GetSound(sound).PlayRandon(); }