0
\$\begingroup\$

This is the Text component settings in the Inspector:

Text

The script DialogueManager:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DialogueManager : MonoBehaviour
{
    public Text dialogueText;
    public float sentencesSwitchDuration;
    public bool animateSentenceChars = false;

    private Queue<string> sentence;

    // Use this for initialization
    void Start ()
    {
        sentence = new Queue<string>();
    }

    public void StartDialogue(Dialogue dialogue)
    {
        Debug.Log("Starting conversation with " + dialogue.name);

        sentence.Clear();
        foreach(string sentence in dialogue.sentences)
        {
            this.sentence.Enqueue(sentence);
        }

        DisplayNextSentence();
    }

    public void DisplayNextSentence()
    {
        if (this.sentence.Count == 0)
        {
            EndDialogue();
            return;
        }

        string sentence = this.sentence.Dequeue();
        dialogueText.text = sentence;

        StopAllCoroutines();
        StartCoroutine(DisplayNextSentenceWithDelay(sentence));
    }

    public IEnumerator DisplayNextSentenceWithDelay(string sentence)
    {
        if (animateSentenceChars)
        {
            dialogueText.text = "";
            foreach (char letter in sentence.ToCharArray())
            {
                dialogueText.text += letter;
                yield return null;
            }
        }

        yield return new WaitForSeconds(sentencesSwitchDuration);
        DisplayNextSentence();
    }

    void EndDialogue()
    {
        Debug.Log("End of conversation.");
    }
}

Then the DialogueTrigger:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DialogueTrigger : MonoBehaviour
{
    public Dialogue dialogue;

    public void TriggerDialogue()
    {
        FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
    }
}

And last Dialogue:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class Dialogue
{
    public string name;

    [TextArea(3, 10)]
    public string[] sentences;
}

Then in the editor in the Dialogue Trigger in the Inspector I added some text to each of the 3 sentences:

Dialogue trigger sentences

Now when I'm running the game the text is changing between the 3 sentences. But since each sentence have different amount of letters(text content) it display it in a different size:

This is the first sentence when the game is running it seems like to me a good size for the text:

Sentence 1

The second sentence. It seems like to me the text size is too small.

Sentence 2

The last sentence is the same size like sentence 2.

How can I make that the text will be the same size in each sentence ? And how can I make that the lines will start from the same position from the left ?

How in other games they are aligning the text ?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Unrelated hint: You probably don't want to have your flying thingy identify itself as 'something something... in the GAME' - it sort of breaks the immersion... unless it's a game about a game that is. \$\endgroup\$
    – dot_Sp0T
    Commented Jul 20, 2018 at 20:02

1 Answer 1

1
\$\begingroup\$

enter image description here

This field, internally, is called resizeTextForBestFit and has the description, "Should the text be allowed to auto resized."

https://docs.unity3d.com/ScriptReference/UI.Text-resizeTextForBestFit.html

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .