Hey all,
I found this neat little script on the UnifyWiki, which sort of types the text of a GUIText out like a typewriter.
var letterPause = 0.2;
private var word;
function Start () {
word = guiText.text;
guiText.text = "";
TypeText ();
}
function TypeText () {
for (var letter in word.ToCharArray()) {
guiText.text += letter;
yield WaitForSeconds (letterPause);
}
}
I would very much like to use this functionality in a GUI.Label, and my question is: can I do that?
I'm afraid I don't possess the necessary experience to adequately judge whether this is an actual possibility or just wishful thinking.
-Veliremus
Edit: Added code to let you add new words on: careful though, it will go a bit iffy if you call the AddText function too quickly before the other finishes, but i'm sure you can use it as an example to make a better one :)
var letterPause = 0.2;
var word = "Test"; // change this one in the inspector
private var currentWord = "";
function Start ()
{
TypeText (word);
}
function AddText(newText : String)
{
word = newText;
TypeText(word);
}
private function TypeText (compareWord : String) {
for (var letter in word.ToCharArray()) {
if (word != compareWord) break;
currentWord += letter;
yield WaitForSeconds (letterPause);
//for added fun, use this instead :D ...
//yield WaitForSeconds(letterPause * Random.Range(0.5, 2));
}
}
function OnGUI()
{
GUI.Label(new Rect(50, 50, 200, 30), currentWord);
}