//Exemple : AudioManager.PlaySound(AudioManager.Sound.THEME_YouWin); public static void PlaySound(Sound sound) { if (!GameAssets.i) { Debug.LogWarning("NO AUDIO MANAGER ON SCENE"); return; } GameAssets.SoundAudioClip soundParameters = GameAssets.i.GetAudioClip(sound); if (soundParameters == null) { return; } GameObject soundGameObject = new GameObject("Sound"); AudioSource audioSource = soundGameObject.AddComponent <AudioSource>(); float volume = 1f; switch (soundParameters.volumeMultiplier.mode) { case ParticleSystemCurveMode.Constant: if (soundParameters.volumeMultiplier.constant > 0) { volume = soundParameters.volumeMultiplier.constant; } break; case ParticleSystemCurveMode.TwoConstants: volume = Random.Range(soundParameters.volumeMultiplier.constantMin, soundParameters.volumeMultiplier.constantMax); break; } float pitch = 1f; switch (soundParameters.pitch.mode) { case ParticleSystemCurveMode.Constant: if (soundParameters.pitch.constant > 0) { pitch = soundParameters.pitch.constant; } break; case ParticleSystemCurveMode.TwoConstants: pitch = Random.Range(soundParameters.pitch.constantMin, soundParameters.pitch.constantMax); break; } audioSource.volume = volume; audioSource.pitch = pitch; audioSource.PlayOneShot(soundParameters.AudioClip); SoundObject soundObj = soundGameObject.AddComponent <SoundObject>(); soundObj.SetAudioSource(audioSource); }
IEnumerator ChangeBackgroundMusic() { foreach (AudioManager.Sound sound in sounds) { GameAssets.SoundAudioClip s_object = Array.Find(GameAssets.Instance.soundsArray, soundObject => soundObject.sound == sound); GameController.Instance.SetBackgroundMusic(sound); yield return(new WaitForSeconds(s_object.audio.length)); } }
public static void PlaySound(Sound sound, Vector3 pos, float radius) { if (CanPlay(sound)) { GameObject soundObject = new GameObject("Sound"); soundObject.transform.position = pos; AudioSource audioSource = soundObject.AddComponent <AudioSource>(); GameAssets.SoundAudioClip AudioClipObject = GetAudioClipObject(sound); audioSource.clip = AudioClipObject.audio; audioSource.volume = AudioClipObject.volume; audioSource.pitch = AudioClipObject.pitch; audioSource.maxDistance = radius; audioSource.spatialBlend = 1f; //Falta regular el volumen audioSource.Play(); Object.Destroy(soundObject, audioSource.clip.length); } }