x


How do I change my 3D Text Value when triggered?

In my game I am developing I attempted to add a script which would change my 3D text value when triggered. Got 2 errors though... :-(

My Code looks like this:

function OnTriggerEnter( hit: Collider)

{

if(hit.gameObject.tag == "Test")

{

var a=GameObject.Find("New Text");

a.GetComponent(TextMesh).text="a";

}

}

But I got an error that said this:

'text' is not a member of UnityEngine.Component'.

When I tried to bypass this I also recieved another error which said something like this (not exact):

Unity Exception. Variable cannot be declared in this function.

Does this have to do with it being Unity iPhone?

Please help by posting a better piece of code or by explaining what is wrong. Thanks alot! :D

more ▼

asked Jun 18 '10 at 01:02 PM

MikezNesh gravatar image

MikezNesh
843 64 74 93

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

1 answer: sort voted first

On iPhone you can't do dynamic typing, so you need to do something like this:

var textMesh : TextMesh = a.GetComponent(TextMesh);
textMesh.text = "a";
more ▼

answered Jun 18 '10 at 01:18 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Thanks alot works perfectly!!! :)

Jun 18 '10 at 01:24 PM MikezNesh

One Question: How could I increment the value on every Collision?

Jun 18 '10 at 01:45 PM MikezNesh

I defined a variable (counter) and an increment (counter ++). But when I do textMesh.text = counter; I get an error response: 'cannot convert "int" to "string"'. How do I solve this issue?

Jun 18 '10 at 01:50 PM MikezNesh

textMesh.text = counter.ToString();

Jun 18 '10 at 02:05 PM Mike 3

Double Thanks! :)

Jun 19 '10 at 12:05 PM MikezNesh
(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:

x5098
x3750

asked: Jun 18 '10 at 01:02 PM

Seen: 7553 times

Last Updated: Jun 18 '10 at 01:02 PM