This is the Text component settings in the Inspector:
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:
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:
The second sentence. It seems like to me the text size is too small.
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 ?