private void TypeNextCharacter(TyperMessage currentMessage, int currentProgress) { var sb = new StringBuilder(); sb.Append(currentMessage.Text.Substring(0, currentProgress)); sb.Append("<color=#ffffff00>"); sb.Append(currentMessage.Text.Substring(currentProgress)); sb.Append("</color>"); _display.text = sb.ToString(); }
void Update() { if (_currentMessage == null) { if (Messages.Count > 0) { _currentMessage = Messages[0]; Messages.Remove(_currentMessage); _timeMessageStarted = Time.time; _currentProgress = 0; } else { return; } } if (_currentProgress <= _currentMessage.Text.Length) { if (!(Time.time > _timeLastTyped + _typeDelay)) { return; } TypeNextCharacter(_currentMessage, _currentProgress); _currentProgress++; _timeLastTyped = Time.time; _typeDelay = AverageTypeDelay * (.5f + UnityEngine.Random.value); } else { if (!(Time.time > _timeMessageStarted + _currentMessage.Duration)) { return; } _currentMessage = null; _display.text = ""; } }