How do you make a text box like they have in pokemon? I managed to make something similar with the following code:
using UnityEngine;
using System.Collections;
using Extensions;
using UnityEngine.UI;
public class DialogController : MonoBehaviour
{
private Text _textComponent;
private string _textToDraw = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam dictum eros ultricies tristique tincidunt. Nulla tristique rhoncus elit vel fringilla. Nunc egestas bibendum risus eget accumsan. Integer mauris";
void Start()
{
_textComponent = gameObject.FindInChildren("Text").GetComponent<Text>();
_textComponent.text = string.Empty;
StartRollingText(_textToDraw,0.1f);
}
public void StartRollingText(string text, float time)
{
StartCoroutine(DrawText(text,time));
}
IEnumerator DrawText(string text,float time) //Keeps adding more characters to the Text component text
{
foreach (char c in text)
{
_textComponent.text += c;
yield return new WaitForSeconds(time);
}
}
}
I should probably use something like substring to boost performance but just to test this out its fine.
There is however a issue with this code. Sometimes when its at the end of a line it can suddenly make the word jump to the next line while its typing it because it gets too long. Now i can probably think of some hacky way to fix this but whats the best practice for this?