public void playSoundLoop(SoundsType soundToPlayLoop) { GameObject audio = Instantiate(audioPrefab); audio.transform.parent = this.transform; audio.GetComponent <Sound>().playLoop(sources[(int)soundToPlayLoop]); }
public void Play(AudioClip audioClip, SoundsType soundtype, float delay) { GameObject go = new GameObject("GameSound"); go.transform.SetParent(gameObject.transform, false); AudioSource source = go.AddComponent<AudioSource>(); source.playOnAwake = false; source.clip = audioClip; switch (soundtype) { case SoundsType.Ambient: source.outputAudioMixerGroup = music; source.loop = true; StopAmbientMusic(); break; case SoundsType.Conversation: case SoundsType.Effect: source.outputAudioMixerGroup = sfx; break; default: break; } source.PlayDelayed(delay); sources.Add(go); }
public void Play(AudioClip audioClip, SoundsType soundtype, float delay) { GameObject go = new GameObject("GameSound"); go.transform.SetParent(gameObject.transform, false); AudioSource source = go.AddComponent <AudioSource>(); source.playOnAwake = false; source.clip = audioClip; switch (soundtype) { case SoundsType.Ambient: source.outputAudioMixerGroup = music; source.loop = true; StopAmbientMusic(); break; case SoundsType.Conversation: case SoundsType.Effect: source.outputAudioMixerGroup = sfx; break; default: break; } source.PlayDelayed(delay); sources.Add(go); }
public void PlaySound(SoundsType soundsType) { var model = soundManagerModel.First(x => x.soundsType == soundsType); var item = pool[0]; item.clip = model.audioClip; item.Play(); pool.RemoveAt(0); pool.Add(item); }
//public void Play(SoundsType type, int sound) //{ // if (type != SoundsType.LOOPING) // { // AudioSource newSource = GetComponent<AudioSource>(); // newSource.PlayOneShot(GetSound(type, sound), 1.0f * gameVolume); // } // else // { // Debug.Log(type + " :: " + sound); // loopSounds[sound].source.volume = 1.0f * gameVolume; // loopSounds[sound].fade = false; // loopSounds[sound].source.Play(); // } //} public void Play(SoundsType type, int sound, float volume) { if (type != SoundsType.LOOPING) { AudioSource newSource = GetComponent <AudioSource>(); newSource.PlayOneShot(GetSound(type, sound), volume * gameVolume); } else { Debug.Log(type + " :: " + sound); loopSounds[sound].source.volume = volume * gameVolume; loopSounds[sound].fade = false; loopSounds[sound].source.Play(); } }
public void PlayRandom(SoundsType type, float volume) { if (type != SoundsType.LOOPING) { AudioSource newSource = GetComponent <AudioSource>(); int sound = Random.Range(0, audioClips[type].Length); newSource.PlayOneShot(GetSound(type, sound), volume * gameVolume); } else { int sound = Random.Range(0, audioClips[type].Length); loopSounds[sound].source.volume = volume * gameVolume; loopSounds[sound].fade = false; loopSounds[sound].source.Play(); } }