【问题标题】:Input from a dynamic input box从动态输入框输入
【发布时间】:2021-11-18 09:15:36
【问题描述】:

我正在尝试将文本添加到 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# unity3d textmeshpro


    【解决方案1】:

    如果您使用 TextMeshPro 输入字段,您要访问的组件应该是 TMP_InputField 而不是 TextMeshProUGUI

    【讨论】:

    • 这非常有效。非常感谢!
    【解决方案2】:

    可以使用 SetText(string text) 方法

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

    【讨论】:

      猜你喜欢
      • 2017-10-23
      • 2016-01-25
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多