x


Text Mesh Scripting

We would like to use a Text Mesh to display a series of words which is highlighted one word at a time.

Any ideas on how this would be done?

My progress so far:

public var textA : String;
           textA += "Once upon a time" \n;
           textA += "there was a little girl.";


function Start() {
      var myTextMesh = (GetComponent(TextMesh) as TextMesh);
      myTextMesh.text = textA;
      renderer.material.SetColor("_Color", Color.red);
}

Thanks!

I appreciate your answer Eric5h5!

We could use it as a fallback technique. However what I was hoping for was for the full text to be on screen and then for each word to highlight as the voice over reads them.

For example all text would be blue and then as each word is read it would become red and then return to its original state.

more ▼

asked Apr 09 '10 at 05:10 PM

Rick gravatar image

Rick
1 1 1 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Use an array of text, and loop through it with a delay after each addition:

var text = ["Once upon a time\n", "there was a little girl."];
var delay = 1.0;

function Start() {
    var myTextMesh = (GetComponent(TextMesh) as TextMesh);
    renderer.material.color = Color.red;
    myTextMesh.text = "";
    for (i = 0; i < text.Length; i++) {
        myTextMesh.text += text[i];
        yield WaitForSeconds(delay);
    }
}
more ▼

answered Apr 09 '10 at 05:47 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5273
x567
x430
x105
x4

asked: Apr 09 '10 at 05:10 PM

Seen: 5348 times

Last Updated: Jun 01 '11 at 11:17 AM