Is the code for obtaining text available

Options

const Scene = require('Scene');

const myText = Scene.root.findFirst('myText');

myText.text = "Hello World!";

Best Answer

  • audun
    audun Posts: 302 🔥🔥🔥
    #2 Answer ✓
    Options

    Hi Bowen!
    If you're trying to edit a Text Component from the Script, you can do this;

    Add a Screen Text (this creates a Orthographic camera)

    Add the Script component to the Orthographic Camera

    Click the red area and select the plus icon next to "Search". Select "Script"

    Copy this code into the Script

    // @input Component.Text text
    
    script.text.text = "changed text from code"
    

    Last step is to select your text layer in the Orthographic Camera.

    Link to Google Drive

Answers

  • hc0
    hc0 Posts: 4
    Options

    كل عام وانت بخير

  • audun
    audun Posts: 302 🔥🔥🔥
    Options

    Hi @bowen wang,
    Are you trying to change the text from a Script?

    If so:

    Create a Script file and add the Component.Text input.

    // @input Component.Text text
    
    script.text.text = "changed text from code"
    

    Create a Screen Text like below.

    Add a Script to the Orthographic Camera

    In the Orthographic Camera, select the Text component you want to update

    You can download the project here.