public static void Play(SoundId snd, Vector3 pos) { //PLog.Info("[Sound] Playing: SoundId.{0}", snd.ToString()); Func <SECTR_AudioCue> cue; if (SOUND_MAP.TryGetValue(snd, out cue)) { SECTR_AudioSystem.Play(cue(), pos, false); } else { SLog.Warn("[Sound] No sound listed for SoundId.{0}", snd.ToString()); } }
/// <summary> /// Plays a sound and sets a timed flag on a given object. /// This is useful for playing a sound in response to an object. /// Example: /// The player fires an object into a garden input that isnt a valid fruit/vegetable. /// The kiosk can use this function to play a negative sound for the item without it playing like 10 times due to the item still being in range of the input area! /// </summary> /// <param name="snd">The sound to play</param> /// <param name="obj">The GameObject to lock the sound so it doesn't play more then once.</param> /// <param name="lockSecs">Number of seconds before the sound can play again.</param> public static void PlayOnce(SoundId snd, GameObject obj = null, float lockSecs = 1.0f) { ObjectFlags locker = obj.GetComponent <ObjectFlags>(); if (locker == null) { locker = obj.AddComponent <ObjectFlags>(); } string flag = String.Concat("soundlock_", snd.ToString()); if (!locker.HasFlag(flag)) { locker.SetFlag(flag, lockSecs); Sound.Play(snd); } }
public static void Play(SoundId snd) { Sound.Play(snd, Vector3.zero); }