I am trying to make a small cutscene with some text shown in the bottom of screen I want the text to appear one word at a time like in RPG games.
I tried using the AutoType script, it works fine when I put it on the guitext and put the text in the guitext using inspector.
But when I use a script like
var textString : GUIText;
function Start {
textString.guiText.text = "Testing";
}
it doesn’t work like its supposed to work with the AutoType script.
For who don’t know about AutoType here is the link and code itself.
var letterPause = 0.2;
var sound : AudioClip;
private var word;
function Start () {
word = guiText.text;
guiText.text = "";
TypeText ();
}
function TypeText () {
for (var letter in word.ToCharArray()) {
guiText.text += letter;
if (sound)
audio.PlayOneShot (sound);
yield WaitForSeconds (letterPause);
}
}
This is because in the Start() method the script actually runs some logic and it launches the TypeText() coroutine. However when you change the text property manually, you do not trigger the effect, TypeText() isn’t called. This is what I advise:
var letterPause = 0.2;
var sound : AudioClip;
private var message;
function Start () {
SetText(guiText.text);
}
function TypeText () {
for (var letter in message.ToCharArray()) {
guiText.text += letter;
if (sound)
audio.PlayOneShot (sound);
yield WaitForSeconds (letterPause);
}
}
function SetText(text : string)
{
StopCoroutine("TypeText");
message = text;
guiText.text = "";
StartCoroutine("TypeText");
}
And from now on, use SetText("message"); to change the text, and it will even stop the current AutoTyping and start it over with the new text.
I am using another script attached to another object to pass the 'string' data to the guittext and I attached this script to the guittext and it gave me errors in line 'function settext(text : string)' here i changed it to String then it gave error in line 12 tochararray not member of object, I changed private var message : String; but now its no error but just same story don't work
I am using another script attached to another object to pass the 'string' data to the guittext and I attached this script to the guittext and it gave me errors in line 'function settext(text : string)' here i changed it to String then it gave error in line 12 tochararray not member of object, I changed private var message : String; but now its no error but just same story don't work
– yusolaifdferGOT IT! I was doing this //var text = textString.GetComponent(autotype); //text.message = "What is happening"; Thank you. Awesome Answer
– yusolaifdfer