unity中如何获得输入框内的值
我想用一个按钮点一下就获得一次输入框InputField1里的值,我这么写的,但是报错了:usingUnityEngine;usingSystem.Collections...
我想用一个按钮点一下就获得一次输入框InputField1里的值,我这么写的,但是报错了:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class savedate : MonoBehaviour
{
public GameObject shuruzhi=GameObject.Find("InputField1");
public string a;
public void Click()
{
a=shuruzhi.text;
Debug.Log (a);
}
}
报错信息是:Assets/Script/savedate.cs(14,28): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `text' and no extension method `text' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
第14行就是a=shuruzhi.text; 展开
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class savedate : MonoBehaviour
{
public GameObject shuruzhi=GameObject.Find("InputField1");
public string a;
public void Click()
{
a=shuruzhi.text;
Debug.Log (a);
}
}
报错信息是:Assets/Script/savedate.cs(14,28): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `text' and no extension method `text' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
第14行就是a=shuruzhi.text; 展开
1个回答
展开全部
a = shuruzhi.transform.GetChild (0).GetComponent<TextMesh> ().text ?
追问
我用这句替代了我原来那句,出现新的报错:UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
追答
你试下用:
public GameObject shuruzhi;
void Start()
{
shuruzhi =GameObject.Find("InputField1");
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询