Browse Source

Fixed characters per second calculation for writing text

Setting Game.charactersPerSecond to zero writes instantly
master
chrisgregan 11 years ago
parent
commit
71eb606014
  1. 27
      Assets/Fungus/Scripts/Page.cs

27
Assets/Fungus/Scripts/Page.cs

@ -107,13 +107,34 @@ namespace Fungus
IEnumerator WriteStoryInternal()
{
float writeDelay = 1f / (float)Game.GetInstance().charactersPerSecond;
int charactersPerSecond = Game.GetInstance().charactersPerSecond;
// Zero means write instantly
if (charactersPerSecond <= 0)
{
displayedStoryText = originalStoryText;
yield break;
}
displayedStoryText = "";
float writeDelay = 1f / (float)charactersPerSecond;
float timeAccumulator = 0f;
while (displayedStoryText.Length < originalStoryText.Length)
{
displayedStoryText += originalStoryText.Substring(displayedStoryText.Length, 1);
yield return new WaitForSeconds(writeDelay);
timeAccumulator += Time.deltaTime;
while (timeAccumulator > 0f)
{
timeAccumulator -= writeDelay;
if (displayedStoryText.Length < originalStoryText.Length)
{
displayedStoryText += originalStoryText.Substring(displayedStoryText.Length, 1);
}
}
yield return null;
}
displayedStoryText = originalStoryText;

Loading…
Cancel
Save