SOLVED here is my code
var letterPause : float = 0.2;
var sound : AudioClip;
private var intDialog : int = 0;
private var word : String;
function Start () {
word = gameObject.guiText.text;
}
function Update () {
if(intDialog == 0){
gameObject.guiText.text = "";
}
if(Input.GetKeyDown("space") DialogTriggerArea.isDialoging){
gameObject.guiText.text = "";
intDialog++;
ShowDialog(DialogTriggerArea.staticTalkingChar);
TypeText();
}
}
function ShowDialog(chara : String){
if(chara == "Dead"){
if(intDialog == 1){
word = "try one try one try one try one try one";
//gameObject.guiText.text = "try one try one try one try one try one";
}
if(intDialog == 2){
word = "try two try two try two try two try two";
//gameObject.guiText.text = "try two try two try two try two try two";
}
if(intDialog == 3){
DialogTriggerArea.isDialoging = false;
intDialog = 0;
}
}
}
function TypeText(){
for(var letter in word.ToCharArray()) {
gameObject.guiText.text += letter;
if(sound){
audio.PlayOneShot(sound);
}
yield WaitForSeconds(letterPause);
}
}