Scrolling typewriter effect

I would like to make a game where the text already been defined, and when I run the game or program, it will display the text, but not fully text on once, but as one word by words. Something like this:

http://wigflip.com/screedbot/ and http://www.youtube.com/watch?v=uFQ6MspAMq8 (The youtube video is already give the example, but it is on c# xna)

Here is one i wrote that i feel works better:

    public Text textBox;

    //Store all your text in this string array
string[] goatText = new string[]{"1. Laik's super awesome custom typewriter script", "2. You can click to skip to the next text", "3.All text is stored in a single string array", "4. Ok, now we can continue","5. End Kappa"};

int currentlyDisplayingText = 0;

void Awake () {
	StartCoroutine(AnimateText());
}

    //This is a function for a button you press to skip to the next text
public void SkipToNextText(){
	StopAllCoroutines();
	currentlyDisplayingText++;
   //If we've reached the end of the array, do anything you want. I just restart the example text
	if (currentlyDisplayingText>goatText.Length) {
		currentlyDisplayingText=0;
	}
	StartCoroutine(AnimateText());
}

   //Note that the speed you want the typewriter effect to be going at is the yield waitforseconds (in my case it's 1 letter for every      0.03 seconds, replace this with a public float if you want to experiment with speed in from the editor)
IEnumerator AnimateText(){
	
	for (int i = 0; i < (goatText[currentlyDisplayingText].Length+1); i++)
	{
		goatTalkingText.text = goatText[currentlyDisplayingText].Substring(0, i);
		yield return new WaitForSeconds(.03f);
	}

}

And that’s it! Works perfectly well and doesn’t clog up Update

I’m assuming you already know how to display text on the screen. Next you need a script that updates this text every frame:

public string textShownOnScreen;
public string fullText = "The text you want shown on screen with typewriter effect.";
public float wordsPerSecond = 2; // speed of typewriter
private float timeElapsed = 0;   

void Update()
{
    timeElapsed += Time.deltaTime;
    textShownOnScreen = GetWords(fullText, timeElapsed * wordsPerSecond);
}

private string GetWords(string text, int wordCount)
{
    int words = wordCount;

    // loop through each character in text
    for (int i = 0; i < text.Length; i++)
    { 
        if (text *== ' ')*

{
words–;
}
if (words <= 0)
{
return text.Substring(0, i);
}
}
return text;
}
The above code updates the textShownOnScreen string to get a typewriter effect. You might want to modify GetWords() in how it counts words - right now any space it encounters in the text it interprets as being a new word… I’m sure there are better ways but this might help you get started.

If you want to show On your textbox also alphabet per frame, then follow this

public class Testing : MonoBehaviour {

    public string textShownOnScreen;
public Text textBox;
public string fullText = "The text you want shown on screen with typewriter effect.";
public float wordsPerSecond = 2; // speed of typewriter
private float timeElapsed = 0;   

void Update()
{

 timeElapsed += Time.deltaTime;

	textShownOnScreen = GetWords(fullText,  timeElapsed * wordsPerSecond);

}

private string GetWords(string text, float wordCount) {
	float words = wordCount;

 // loop through each character in text
 for (int i = 0; i < text.Length; i++)
 { 
		
 
			words--;
			textBox.text = textShownOnScreen;

     
     if (words <= 0)
     {
         return text.Substring(0, i);
     }
 }
 return text;

}
}

In the provided code do this:
public float wordsPerSecond = 2f; // speed of typewriter
private float timeElapsed = 0f;

This was very handy, I still don’t get the return text.Substring(0, i); and return text; but it works and I will slowly figure out why.