how to make text that is writen automatically, letter by letter

I have a little problem.

How can i make a text that is written by himself. I mean that i have the text, but to make it as an animation like this. ModernCombat2 As you can see in the first seconds, the text is written by himself. how can i do that in my own game?

Here’s a C# example that works in Unity 5.1.1 using Unity’s new UI system:

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

public class TextTyper : MonoBehaviour {

	public float letterPause = 0.2f;
	public AudioClip typeSound1;
	public AudioClip typeSound2;

	string message;
	Text textComp;

	// Use this for initialization
	void Start () {
		textComp = GetComponent<Text>();
		message = textComp.text;
		textComp.text = "";
		StartCoroutine(TypeText ());
	}

	IEnumerator TypeText () {
		foreach (char letter in message.ToCharArray()) {
			textComp.text += letter;
			if (typeSound1 && typeSound2)
				SoundManager.instance.RandomizeSfx(typeSound1, typeSound2);
				yield return 0;
			yield return new WaitForSeconds (letterPause);
		}
	}
}

SoundManager and Loader scripts (based on the examples found in Roguelike tutorial) found here: Loader and SoundManager scripts referenced in TextTyper class · GitHub

Well, that's quite simple. Just store your text in a script variable. A coroutine can copy it char by char.

edit: Added additionalLines variable

It should work… not tested!

var currentPosition : int = 0;
var Delay : float = 0.1;  // 10 characters per sec.
var Text : String = "";
var additionalLines : String[];

function WriteText(aText : String) {
    guiText.text = "";
    currentPosition = 0;
    Text = aText;
}

function Start(){
    for ( var S : String in additionalLines )
        Text += "

" + S;
while (true){
if (currentPosition < Text.Length)
guiText.text += Text[currentPosition++];
yield WaitForSeconds (Delay);
}
}

@script RequireComponent(GUIText)

From within this script just use:

WriteText("This is the first line 
 this is the second line 
 maybe a third?");

To set the text from another script you have to get your script instance first. Note: in this example the script is named "AutoText".

GetComponent.<AutoText>().WriteText("first line 
 second line");

To write a new text just call WriteText() with your text as parameter. This script uses a GUIText component.

If you want, the extension “TTF Text” that generates text meshes does it directly out of the box, with sound, and for any layout and font. Various other effects are also possible. Check this video : http://youtu.be/RzdjQStYkmU

#pragma strict
public var output : String = “”;
var Delay : float = 0.05; // 10 characters per sec.
private var Text : String;
public var doubleSpace : boolean = false;

function WriteText(aText : String[]) {
    output = "";
    Text = aText;
//   TypeText();
   StartCoroutine("TypeText");
}

function TypeText () {
   for (var word : String in Text) {
      for (var letter in word.ToCharArray()) {
         output += letter;
         yield WaitForSeconds (Delay);
      }
      output += "

";
if (doubleSpace)
output += "
";
}
}

Attach this script to any GameObject that contains GUI elements to be “typed” into. If a button launches the display of text, make sure to place this.GetComponent().WriteText(ARRAY_OF_TEXT); within the button execution. If no button is being used, this line may also be placed in the Start function.

ARRAY_OF_TEXT should be a standard string array separated by line. The text parameter for the GUIText, GUILabel, or GUIButton to have text typed into would then be this.GetComponent().output.

Enabling double space will separate each line by two line breaks.

hey guys i think this autotype script need somthing … im talking about the NEXT button for EXample if you try to make a text that contain a lot of lines like talking messages in the rpg games ets … how dose it made??

Here’s my take on it. Taking inspiration on Lampd1’s answer. It had one issue for me: it doesn’t work whole using formatting like “Hello, < b> playerName < /b>.” as the formatting’s character will appear for a little bit while the characters are being physically added. I just used TMPro’s maxVisibleCharacter to make it work:

using System.Collections;
using UnityEngine;
using TMPro;

public class Test : MonoBehaviour
{
    TMP_Text dialogText;
    private string text;
    private float letterDelay = 0.05f;

    public void WriteText()
    {
        dialogText.maxVisibleCharacters = 0; //Resets whenever this is re-used.
        dialogText.text = text;
        StartCoroutine(TypeText());
    }

    IEnumerator TypeText()
    {
        for (int i = 0; i < dialogText.text.Length; i++)
        {
            dialogText.maxVisibleCharacters++;
            yield return new WaitForSeconds(letterDelay);
        }
    }
}

You can use this as base:

You could buy this. It will open Unity and the the asset store...