Is it the best way ?

Hi, I’ve created a subtitle that writing words one after one, I’ve used my method for this but I think it isn’t the best way that I could do to create such a thing like that

This code will writing My Name Is Ash

yield WaitForSeconds (13);



yield WaitForSeconds (0.04);
guiText.text = "M";
       
yield WaitForSeconds (0.04);
guiText.text = "My";

yield WaitForSeconds (0.04);
guiText.text = "My N";

yield WaitForSeconds (0.04);
guiText.text = "My Na";

yield WaitForSeconds (0.04);
guiText.text = "My Nam";

yield WaitForSeconds (0.04);
guiText.text = "My Name";

yield WaitForSeconds (0.04);
guiText.text = "My Name I";
       
yield WaitForSeconds (0.04);
guiText.text = "My Name Is";

yield WaitForSeconds (0.04);
guiText.text = "My Name Is A";

yield WaitForSeconds (0.04);
guiText.text = "My Name Is As";

yield WaitForSeconds (0.05);
guiText.text = "My Name Is Ash";

yield WaitForSeconds (2);
guiText.text ="";

}

This worked good but Isn’t there any better way?

Can you think about less question marks? It’s needlessly attention-seeking and I don’t think you’re more important than someone who asks politely and clearly.

ps he technique you’re using is stupid. Just add letters to strings. And I don’t think you deserved that answer.

You could do something like this (pseudo code):

Declare a string variable assigning the complete text.
Declare a float variable that will accumulate the delta time.
Declare a float variable that will store the time each character will wait to appear.
Declare a int variable to store the amount of letters to show.

In the Update method:
Increase the time variable adding the delta time.
If time variable is greater than wait time then
reset to zero the time variable
increment the amount letter variable
split the text by the amount of letters to show and store it into a temp variable
assign to the gui text the parsed text
end if

erm, no, and putting a bunch of ??? on the end of your title is very irritating.

function TypeText(text:String){
	var i:int=1;
	while(i<text.Length){
		guiText.text = text.Substring(0,i);
		yield WaitForSeconds(0.05);
		i++;
	}
	yield WaitForSeconds(2);
	guiText.text = "";
}

Thanks guys and sorry for ???

Thanks a lot for code but where should I put my text? It doesn’t show anything
I’m felling like a toddler kid after seeing your code :smile:

the text is passed as a parameter (the bit in the brackets on the first line)… so you call

TypeText(“My name is Ash”);

I delete your “??? ???” and hope to never see that again.

Thanks a lot LeftyRighty
And an especial thanks to bigmisterb
thanks