Skip to main content Scroll Top
  1. Home
  2. Docs
  3. 3D Text Suite - Basics
  4. Setting Text From Script

Setting Text From Script

after you have created a 3D Text object you may want to trigger it via script. Here is how you can do that:

Obtaining a 3D Text Object for scripting

//add a public Text3D to your monobehaviour
public Text3D myText;

On the inspector , Drag the a 3D Text Object into the monobehavior myText field:

you can now use myText in your monobehaviour

Setting text and rich text via script

myText.SetText("My 3D Text"); // set a simple 3d Text using the current font settings
myText.SetText("My 3D Text",true); //set the text but do not animate

for rich text, you need to build a 3d text span. Add the following fields to your monobehaviour

    public Font3DStyle firstFont; // the first font to set
    public Font3DStyle secondFont; // the second font to set

now do this

            var builder = new RichTextSpan.Builder();
            //add each font and text.
            builder.AddSpan(firstFont, 1.5f, firstFontText); // first font with size 1.5
            builder.AddSpan(secondFont, 1f, secondFontText); // second font with size 1
            var richText = builder.Build(); // call builder.Build() to get the richTextSpan
            myText.SetText(richText); // set the text

You can find an example of calling SetText from script it Basics/Tutorials/Set Text and Basics/Tutorials/Rich Text

How can we help?