C#中的Unity GUI TextField
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#中的Unity GUI TextField,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1517字,纯文字阅读大概需要3分钟。
内容图文
![C#中的Unity GUI TextField](/upload/InfoBanner/zyjiaocheng/786/6c3b7d499a484f8886810bf978109230.jpg)
所以我在Unity中制作一个注册场景,当我使用这个脚本放置文本字段和一个按钮时,但是当我播放时我无法输入文本字段.我的代码出了什么问题?
void OnGUI () {
string email = "";
string username = "";
string password = "";
string confirm = "";
email = GUI.TextField (new Rect (250, 93, 250, 25), email, 40);
username = GUI.TextField ( new Rect (250, 125, 250, 25), username, 40);
password = GUI.PasswordField (new Rect (250, 157, 250, 25), password, "*"[0], 40);
confirm = GUI.PasswordField (new Rect (300, 189, 200, 25), confirm, "*"[0], 40);
if (GUI.Button (new Rect (300, 250, 100, 30), "Sign-up")) {
Debug.Log(email + " " + username + " " + password + " " + confirm);
}
}
解决方法:
将输入变量存储为类/脚本的成员,而不是方法.您将每个帧重置为空字符串,消除用户尝试输入的内容.
关于text参数的Unity3D documentation注释:
Text to edit. The return value of this function should be assigned
back to the string as shown in the example.
尝试将代码更改为:
//notice these are pulled out from the method and now attached to the script
string email = "";
string username = "";
string password = "";
string confirm = "";
void OnGUI () {
email = GUI.TextField (new Rect (250, 93, 250, 25), email, 40);
username = GUI.TextField ( new Rect (250, 125, 250, 25), username, 40);
password = GUI.PasswordField (new Rect (250, 157, 250, 25), password, "*"[0], 40);
confirm = GUI.PasswordField (new Rect (300, 189, 200, 25), confirm, "*"[0], 40);
if (GUI.Button (new Rect (300, 250, 100, 30), "Sign-up")) {
Debug.Log(email + " " + username + " " + password + " " + confirm);
}
}
内容总结
以上是互联网集市为您收集整理的C#中的Unity GUI TextField全部内容,希望文章能够帮你解决C#中的Unity GUI TextField所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。