Instantiate and edit a text box during runtime

I’m trying to make it so that users can create a text box in worldspace when they start typing on the keyboard.

So far I have a prefab containing a Text(Script) component which has all the desired text box preferences. I’m having trouble figuring out how exactly the player can access the text field in this box and edit it during gameplay. So far the closest thing I’ve gotten is having a separate TextArea in the GUI and then passing that string to the text in the Text(Script) component, but surely there’s a better way.

Here’s a screenshot to help illustrate what I’ve gotten so far. The TextArea is the entry field on the top left of the screen and the floating text in the worldspace is the text box whose text I want to edit during runtime.

Use GetComponent() to get the Text component on the prefab.

By modifying Text.text, the text of the component will change.

A simple script would look something like this:

public GameObject textPrefab;
Text textPrefabText;

void Start() {
textPrefabText = textPrefab.GetComponent<Text>();

textPrefabText.text = "Woohoo! I'm writing text at runtime!";

But if you want to modify it in one line of code, you would do this:

void Start() {
    textPrefab.GetComponent<Text>().text = "Woohoo! I'm writing text at runtime!";