Dialog Upgrade (Part 2)

Dialog Upgrade (Part 2)

Andrew Velez
Posted on 12/21/2018Last Modified: 1/20/2019



I added a button that lets the player know when he is able to move on to the next speech bubble. It's a simple problem to fix, i'll be sharing what i did in this article.

First i setup my dialog to have my text be left and top aligned. This made it so the text comes from left to right and top to bottom when words come out. I believe this looks best for when you are rendering multiple words in a row.

What my text alignment looks like i Unity.

My settings for the Dialog text.

The only thing that is really relevant in that image is the alignment since that is what helps the text come out correctly and not overlap the button when it's rotating. Horizontal Overflow will tell the text to wrap to the next line if it gets bigger than the width. I don't want the text to show if it is to long vertically so i Truncate.






{alt}

Dialog Button transform plus view in Unity Viewport


This next image shows what the transform for the button looks like. It needs to be anchored correctly so that when the game scales the button is still in the same location (the bottom right).



The code below is the most important part to making the button useful. First i call this method using a couroutine. StartCouroutine(UpdateText());

private IEnumerator UpdateText()
{
    // Make sure player can currently talk if not return
    if(currentText >= allText.Length)
    {
        yield return null;
    }

    // While were not showing the full text.
    while(displayText != allText[currentText])
    {

        // If were currently displaying some text it means we have started speaking. Keep adding the rest of the text 
        // to display. Basically shows one letter every 0.02 seconds.
        if (displayText != string.Empty)
        {
            var length = Mathf.Min(displayText.Length + 1, allText[currentText].Length);
            displayText = allText[currentText].Substring(0, length);
        }

        // We just started speaking. Start text with first 12 letters.
        else
        {
            var length = Mathf.Min(12, allText[currentText].Length);
            displayText += allText[currentText].Substring(0, length);
        }

        DialogText.text = displayText;
        yield return new WaitForSeconds(0.02f);
    }

    // Finished talking now move on to next text and allow the user to skip the dialog.
    currentText++;
    canSkip = true;
}

Andrew Velez
Posted on 12/21/2018Last Modified: 1/20/2019

...

Recomendations

Games for Sale

Comments 0

Display Name

Email


0 / 10