protected void Awake() { globalSounds = GetComponent <SoundHolder>(); if (instance != null) { GameObject.DestroyImmediate(instance); } instance = this; }
private static SoundInfo GetSoundInfo(SoundHolder soundHolder, string name) { name = name.ToUpper(); for (int i = 0; i < soundHolder.sounds.Length; i++) { if (name.Equals(soundHolder.sounds[i].name.ToUpper())) { return(soundHolder.sounds[i]); } } Debug.LogError("Could not find sound: " + name); return(null); }
public static void PlaySoundEffect(SoundHolder soundHolder, string soundEffectName) { var audio = CreateAudioSource(); audio.spatialize = false; var info = GetSoundInfo(soundHolder, soundEffectName); var clip = info.clips[Random.Range(0, info.clips.Length)]; audio.clip = clip; audio.volume = info.volumeMod; audio.pitch = GetPitch(info.pitchVariance); audio.Play(); Destroy(audio.gameObject, clip.length * audio.pitch + 1f); }
public static void PlaySoundEffect(SoundHolder soundHolder, string soundEffectName, float volume, Vector3 pos, float pitch) { var audio = CreateAudioSource(); audio.transform.position = pos; var info = GetSoundInfo(soundHolder, soundEffectName); var clip = info.clips[Random.Range(0, info.clips.Length)]; audio.spatialBlend = 1f; audio.clip = clip; audio.volume = info.volumeMod * volume; audio.pitch = pitch * GetPitch(info.pitchVariance); audio.Play(); Destroy(audio.gameObject, clip.length * audio.pitch + 1f); }
public static void PlaySoundEffect(SoundHolder soundHolder, string soundEffectName, float volume, Vector3 pos) { var info = GetSoundInfo(soundHolder, soundEffectName); if (info == null || info.clips.Length == 0) { Debug.LogError("No sound effects for " + soundEffectName); return; } var audio = CreateAudioSource(); audio.transform.position = pos; var clip = info.clips[Random.Range(0, info.clips.Length)]; audio.spatialBlend = 1f; audio.clip = clip; audio.volume = info.volumeMod * volume; audio.pitch = GetPitch(info.pitchVariance); audio.Play(); Destroy(audio.gameObject, clip.length * audio.pitch + 1f); }