如何从 UI.InputField 获取文本?

How to get Text from UI.InputField?

我想从 UI InputField 中检索文本,但我不确定如何。

您可以先以某种方式获取对游戏对象的引用,然后从中获取 InputField 组件并获取组件的 text 变量:

    GameObject inputFieldGo = GameObject.Find("PathToTheGameObject");
    InputField inputFieldCo = inputFieldGo.GetComponent<InputField>();
    Debug.Log(inputFieldCo.text);