refactor: initialise int before the loop

This commit is contained in:
Antoine Papillon
2026-03-13 11:16:25 +01:00
parent ceb4c54b9d
commit 2dbe21ec62

View File

@@ -144,12 +144,13 @@ public class SubtitleSequencePlayer : MonoBehaviour
float typeTime = 0f; float typeTime = 0f;
int totalChars = line.text.Length; int totalChars = line.text.Length;
int visibleChars = 0;
if (typewriterCharsPerSecond > 0f) if (typewriterCharsPerSecond > 0f)
{ {
while (m_currentText.Length < totalChars) while (m_currentText.Length < totalChars)
{ {
typeTime += Time.deltaTime; typeTime += Time.deltaTime;
int visibleChars = Mathf.Clamp(Mathf.FloorToInt(typeTime * typewriterCharsPerSecond), 0, totalChars); visibleChars = Mathf.Clamp(Mathf.FloorToInt(typeTime * typewriterCharsPerSecond), 0, totalChars);
m_currentText = line.text.Substring(0, visibleChars); m_currentText = line.text.Substring(0, visibleChars);
yield return null; yield return null;
} }