public void UpdateSound() { Sound2D.Adapt2DSound(audioSource); audioSource.maxDistance = maxDistance; audioSource.minDistance = minDistance; }
public void Play(AudioClip clip, float volume = 1f) { if (!audioSource) { audioSource = gameObject.AddComponent(typeof(AudioSource)) as AudioSource; Sound2D.Adapt2DSound(audioSource); audioSource.clip = clip; audioSource.volume = volume; audioSource.loop = false; audioSource.maxDistance = 15f; audioSource.minDistance = 5f; audioSource.Play(); } }
public void PlayEffect(string effectName, float volumeSound = -1f) { volumeSound = volumeSound == -1 ? volume : volumeSound; EffectElement found = foundEffect(effectName); if (found.name != null) { AudioSource newAudio = gameObject.AddComponent(typeof(AudioSource)) as AudioSource; Sound2D.Adapt2DSound(newAudio); newAudio.maxDistance = maxDistance; newAudio.minDistance = minDistance; newAudio.clip = found.variants[Random.Range(0, found.variants.Count)]; newAudio.volume = volumeSound; newAudio.Play(); newAudio.loop = false; allSourcesSoundsEffects.Add(newAudio); } }
public void PlaySound(string musicName, float speedTime = 10f) { SoundElement found = foundSound(musicName); if (found.name != null && found.name != currentName) { //We have found a sound currentName = found.name; timeToTransition = speedTime; currTimeTransition = timeToTransition; AudioSource newAudio = gameObject.AddComponent(typeof(AudioSource)) as AudioSource; Sound2D.Adapt2DSound(newAudio); newAudio.maxDistance = maxDistance; newAudio.minDistance = minDistance; newAudio.clip = found.clip; newAudio.volume = 0f; newAudio.Play(); newAudio.loop = found.loop; allSources.Add(newAudio); InitVolumes(); } }