help with making text display letter by letter

first off if anyone knows an easy way to make a string display one letter at a time please tell me, it will greatly be appreciated.

next i have been trying my own way which is i wanted to feed each letter of a preset string into a new string which would then be displayed.

anyway now i’m not sure how to accomplish this, i can’t figure out an easy way to feed each letter of a string into another string, does anyone have any advice?

Sounds like the “game over” routine I did for this. (Line 264 of the InvaderControl script.) It also adds a space between each letter, which you probably want to take out.

–Eric

ah i see, thanks that’s exactly what i needed.

thanks you, saved me alot of head aches lol

I know this is a very old topic, so I apologize for bumping it, but it’s the only one I’ve found so far that is related.

I’m attempting to do the letter-by-letter text display in C#, but for some reason, my IEnumerable function I created to delay each letter will not accept an argument. It keeps setting the value of the parameter to 0 when the debugger steps to it, when it should be some other value. I’m also open to any code critique, as I’m fairly new to Unity. Here is the entirety of my script:

using UnityEngine;
using System.Collections; 

public class Instructions : MonoBehaviour {
	
	public string [] instructionsLine; // Add your text in the inspector, not within this script.
	public string message, newMessage;
	public float delayInSeconds;
	bool wholeMessagePrinted;
	GUIText printedInstruction;
	GameObject go;
	
	void Start () 
	{
		go = new GameObject("instructionLinesGameObj");
		wholeMessagePrinted  = false;
        delayInSeconds = 1.0f; // for testing purposes, made this value larger than it should be.	
		printedInstruction = (GUIText)go.AddComponent(typeof(GUIText));
		printedInstruction.text = "";
	}
	
	void OnGUI () 
	{
		Rect r = guiText.GetScreenRect();
		
		if (wholeMessagePrinted == false)
		{
			for (int i = 0; i < instructionsLine.Length; i++)
			{
				// Step through the array, and get each string to be written.
				message = instructionsLine[i];
				
				for (int j = 0; j < message.Length; j++)
				{
					// step through the message letter-by-letter, feeding it to the GUIText obj.
					newMessage += message[j];
					// apply the new text to the GUIText object
					printedInstruction.text = newMessage;
					// re-place the object
					printedInstruction.pixelOffset = new Vector2(-(r.width/2), Screen.height/2);
					printedInstruction.enabled = true;
					
					// introduce the messages one letter at a time for snazzy effect!
					delayText(delayInSeconds);
				}
				// add a new line between messages.
				newMessage += "\n";
			}
			wholeMessagePrinted = true; //set flag
		}
		
	}
	
	IEnumerable delayText(float delay)
	{
	    yield return new WaitForSeconds(delay);
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

Hey Roddyt, you might want to check HOTween (sorry for the shameless self-promotion, but anyway it’s a free tool, and the best answer I could come up with), which can also animate string variables letter by letter :slight_smile: