- Home /
Change Textmesh.text from script
Ok, I've checked every other answer I could find on this and nothing is working.
I have a GameObject that is a Sphere named "Sphere". Sphere has a TextMesh child object called "MyText".
Sphere has a .js script attached. I want the Start function to set the TextMesh.text property to "Hello". I have tried every answer I could find on here and in the Unity reference. The ones that do compile without error do nothing, the rest as I said produce errors along the line of 'Semicolon expected' when the statements are definitely ended with a semicolon.
Ideas?
EDIT: Ok, I got it working by giving the TextMesh its own script and placing the statements into the Update function of that script.
My question is now how can I access the properties of a GameObject B from a script running on GameObject A? Do I have to put a script onto GameObject B?
Answer by SvenEV · Aug 12, 2012 at 07:04 PM
Have a look at the method transform.Find(...). In your example you could access "MyText" from a script attached to "Sphere" like this:
transform.Find("MyText")
Answer by Sundar · Aug 12, 2012 at 05:33 PM
From script running on GameObject A
other : ScriptName;
other = GameObject.Find( "B" ).GetComponent(ScriptName);
other.function();
other.a_variable;
function() and a_Variable should be public
Your answer
Follow this Question
Related Questions
If Statements with PlayerPrefs 1 Answer
Display Emojis using its HTML code in a text 1 Answer
Is it possible to make textMeshProGui text to toggle with the unity editor gizmo's button? 0 Answers
TextMeshPro smallcaps option is converting "i" to "İ" not "I", why ? 1 Answer
I can't change the text mesh 1 Answer