Issue with text wrapping, adding one character at the time but need to know if next word will fit.

Hi,

I’ve been googling this issue for three days now before deciding to post here. I’m going to show a gif and explain my issue.


(if gif doesn’t work: Imgur: The magic of the Internet)

As you can see I’m adding one character at the time and my issue is with the word “opportunity” that’s starts on the first row but when it isn’t going to fit it jumps down one row.

I’m wondering if.. there’s a way for me to know how many characters the next word is going to be and how many characters there’re left before it’s going to jump down one row.

If you want to alter the wrapping logic for text, you’ll need to make your own version of the Text control (copied from the original in the bitbucket source)
It currently wraps per letter, which each are individual meshes. If you need it more advanced, you’ll have to update it yourself I’m afraid.

Either that, in your code where you are revealing one character at a time, if you work out the next work isn’t going to fix (approximation should be fine), then add a “New Line” character to force it to start a new line and then continue. Not tried that personally but it should work as an alternative.

Thanks for the tips SimonDarksideJ, I did however tried another solution that worked for me. Going to post my solution below if others would find this thread.

IEnumeratorWriteMessage(string newMessage)
{
newMessage = newMessage.Replace ("*", "\n");
foreach (char c in newMessage) {
if(c == '*'){
message.TrimEnd('*');
message += '\n'.ToString();
}else{
message += c;
}
yieldreturnnewWaitForSeconds(0.05f);
}
}
1 Like