# AutoType script problem.

**URL:** https://discussions.unity.com/t/autotype-script-problem/60220
**Category:** Questions & Answers
**Created:** [January 12, 2013, 2:51pm UTC](https://discussions.unity.com/t/autotype-script-problem/60220 "2013-01-12T14:51:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yusolaifdfer](https://avatars.discourse-cdn.com/v4/letter/y/2bfe46/32.png) [@yusolaifdfer](https://discussions.unity.com/u/yusolaifdfer)
#### Post date: [January 12, 2013, 2:51pm UTC](https://discussions.unity.com/t/autotype-script-problem/60220/1 "2013-01-12T14:51:28Z")

</div>

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);
	}		
}

```

[http://wiki.unity3d.com/index.php?title=AutoType](http://wiki.unity3d.com/index.php?title=AutoType)

---

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [January 12, 2013, 3:19pm UTC](https://discussions.unity.com/t/autotype-script-problem/60220/2 "2013-01-12T15:19:49Z")

</div>

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.
