How to display 1 letter at a time

I want to have this effect that displays one letter at a time 1/4 of a second after the last one.

For example:

it displays “C”.
1/4 of a second later, it then displays “L”.
1/4 of a second after that, it displays “E”.

etc…

How do I do this using GUI scripting?

you could do this a number of ways. maybe have an int variable “letterShow”. have letterShow increase by 1 every 1/4 or a second.
then in the GUI, make an if statement for each letter:
if (letterShow >= 1)
//draw “C”
if (letterShow >= 2)
//draw “L”

and so on…

var text = "Blah blah blah";
var delay = .25;
private var currentText = "";

function OnGUI () {
	if (GUILayout.Button("Typewriter")) TypeText();
	GUILayout.Label(currentText);
}

function TypeText () {
	currentText = "";
	for (c in text) {
		currentText += c;
		yield WaitForSeconds(delay);
	}
}

That code seems to only work when the button is pressed, and doesn’t work for what I want…

I have a certain variable, and when that number reaches 0, I want it to start this. I tried to edit the code you supplied, but it didn’t seem to work :frowning:

any ideas?

I have a script that does this, which I’m pretty proud of. Let me go dig that up and paste the important parts:

public IEnumerator DialougeCoroutine()
    {
        isStarted = true;
        while (dialougeQueue.Count > 0)
        {
            currentDialougeRequest = dialougeQueue.Dequeue();
            for (int i = 0; i < currentDialougeRequest.Dialouge.Length + 1; i++)
            {
				if (textSound != null)
					audio.PlayOneShot(textSound);
					
                currentDialougeIndex = i;
                yield return new WaitForSeconds(0.02f);
            }
            yield return new WaitForSeconds(3f);
        }       

        isStarted = false;
    }

In the Draw method, I just do this:

string typedDialouge = currentDialougeRequest.Dialouge.Substring(0, currentDialougeIndex);

which gives me the text as it currently appears. I pop it through a GUI.Label to display it onscreen.

This example is pretty coupled into my own game (and has a message queuing system that I didn’t get into), but I think you get the basic idea.

no offense, but I am soooo confused by that script. I have absolutely no idea what most of that stuff means :stuck_out_tongue:

Do you maybe have something a bit more simple?