Unity3D用c#读取输入框数据
1,
Dictionary<string,string> textFromMyInputs = new Dictionary<string,string>();//字典存放输入框名称和内容
public Text Text1, Text2;//显示对应输入框的内容
public void GetAllTextFromInputFields()
{
foreach (InputField inputField in gameObject.GetComponentsInChildren<InputField>())//查找下面输入框子物体
{
foreach (Text text in inputField.GetComponentsInChildren<Text>())//输入框下面有两个文本
{
if (text.gameObject.name != "Placeholder")//排除图中那个,剩下的就是我们需要的
textFromMyInputs.Add(inputField.name,text.text);
if (inputField.gameObject.name == "InputField1")
Text1.text = text.text;
if (inputField.gameObject.name == "InputField2")
Text2.text = text.text;
}
}
foreach (var s in textFromMyInputs)//循环输出
{
Debug.Log(s);
}
}
版权声明:本文为weixin_45565630原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。