From 2b8d0cd87e7452f03cbb694b50fa83649edf4343 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Fri, 20 Sep 2019 20:55:53 +1000 Subject: [PATCH] Writer character delay counter modification - more consistent character pacing - prevents the 1 character per frame limit, fixed by timer increment after return from yield --- Assets/Fungus/Scripts/Components/Writer.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Assets/Fungus/Scripts/Components/Writer.cs b/Assets/Fungus/Scripts/Components/Writer.cs index b0015dbb..6052b34e 100644 --- a/Assets/Fungus/Scripts/Components/Writer.cs +++ b/Assets/Fungus/Scripts/Components/Writer.cs @@ -495,6 +495,7 @@ namespace Fungus UpdateCloseMarkup(); float timeAccumulator = Time.deltaTime; + float invWritingSpeed = 1f / currentWritingSpeed; for (int i = 0; i < param.Length + 1; ++i) { @@ -510,6 +511,7 @@ namespace Fungus yield return null; } + //actually grab the next chars PartitionString(writeWholeWords, param, i); ConcatenateString(startText); textAdapter.Text = outputString.ToString(); @@ -533,13 +535,19 @@ namespace Fungus // Delay between characters if (currentWritingSpeed > 0f) { - if (timeAccumulator > 0f) + timeAccumulator -= invWritingSpeed; + if (timeAccumulator <= 0f) { - timeAccumulator -= 1f / currentWritingSpeed; - } - else - { - yield return new WaitForSeconds(1f / currentWritingSpeed); + if (invWritingSpeed > Time.deltaTime) + { + yield return new WaitForSeconds(invWritingSpeed); + timeAccumulator += invWritingSpeed; + } + else + { + yield return null; + timeAccumulator += Time.deltaTime; + } } } }