首页 > 解决方案 > 从动态输入框输入

问题描述

我正在尝试将文本添加到 Unity 中的动态输入框。我正在使用 Text Mesh Pro 资产。输入框在我想要的位置创建,但文本不显示。

代码如下:

在此处输入图像描述

public GameObject inputs;
public GameObject beginplek;

// Start is called before the first frame update
public void Start()
{
    GameObject newinput = Instantiate(inputs, beginplek.transform.localPosition, beginplek.transform.localRotation) as GameObject;
    newinput.transform.SetParent(GameObject.FindGameObjectWithTag("aaaa").transform, false);
    newinput.name = "periode12";
    GameObject.Find("periode12").GetComponent<TextMeshProUGUI>().text = "Hello World";
}

标签: c#unity3dtextmeshpro

解决方案


您可以使用 SetText(string text) 方法

GameObject.Find("periode12").GetComponent<TextMeshProUGUI>().SetText("Hello World");

推荐阅读