From 13f1aaa161f663b296e0ebac6b175289d5a2a34b Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 19 Oct 2015 12:32:28 +0100 Subject: [PATCH] Fixed Writer beep timing issues in WebGL #295 --- Assets/Fungus/UI/Scripts/WriterAudio.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Assets/Fungus/UI/Scripts/WriterAudio.cs b/Assets/Fungus/UI/Scripts/WriterAudio.cs index da85f431..eb0f3b52 100644 --- a/Assets/Fungus/UI/Scripts/WriterAudio.cs +++ b/Assets/Fungus/UI/Scripts/WriterAudio.cs @@ -46,6 +46,9 @@ namespace Fungus // True when a voiceover clip is playing protected bool playingVoiceover = false; + // Time when current beep will have finished playing + protected float nextBeepTime; + public virtual void SetAudioMode(AudioMode mode) { audioMode = mode; @@ -210,7 +213,7 @@ namespace Fungus { Stop(); } - + public virtual void OnGlyph() { if (playingVoiceover) @@ -222,9 +225,17 @@ namespace Fungus { if (!targetAudioSource.isPlaying) { - targetAudioSource.clip = beepSounds[Random.Range(0, beepSounds.Count - 1)]; - targetAudioSource.loop = false; - targetAudioSource.Play(); + if (nextBeepTime < Time.realtimeSinceStartup) + { + targetAudioSource.clip = beepSounds[Random.Range(0, beepSounds.Count - 1)]; + targetAudioSource.loop = false; + targetVolume = volume; + targetAudioSource.Play(); + + float extend = targetAudioSource.clip.length; + + nextBeepTime = Time.realtimeSinceStartup + extend; + } } } }