简体   繁体   English

Unity使用带有输入字段的脚本

[英]Unity use script with the input fields

I have a PHP script and a .cs script which is basically a login/user. 我有一个PHP脚本和一个.cs脚本,基本上是一个登录名/用户。 But I want to use it with the fields in the app and not custom made ones with the code. 但我想将其与应用程序中的字段一起使用,而不是与代码一起定制。

Here is a image of what im talking about 这是我正在谈论的图像

Image link 图片链接

here is my .cs code 这是我的.cs代码

  if (register)
        {
            GUILayout.Label("Username");
            user = GUILayout.TextField(user);
            GUILayout.Label("Name");
            name = GUILayout.TextField(name);
            GUILayout.Label("password");
            password = GUILayout.PasswordField(password, "*"[0]);
            GUILayout.Label("Re-password");
            rePass = GUILayout.PasswordField(rePass, "*"[0]);

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Back"))
                register = false;

            if (GUILayout.Button("Register"))
            {
                message = "";

                if (user == "" || name == "" || password == "")
                    message += "Please enter all the fields \n";
                else
                {
                    if (password == rePass)
                    {
                        WWWForm form = new WWWForm();
                        form.AddField("user", user);
                        form.AddField("name", name);
                        form.AddField("password", password);
                        WWW w = new WWW("http://dri********.com/register.php", form);
                        StartCoroutine(registerFunc(w));
                    }
                    else
                        message += "Your Password does not match \n";
                }
            }

            GUILayout.EndHorizontal();
        }

So right now its displaying new boxes but I want it to use my current inputfields that are in my design 因此,现在它显示新框,但我希望它使用设计中的当前输入字段

GUILayout in code creates those fields at runtime, you will need to get rid of them. 代码中的GUILayout在运行时创建这些字段,您将需要摆脱它们。

In a new class maybe,attached to a gameobject in the inspector: 在一个新的类中,可能附加到检查器中的游戏对象上:

//Add a namespace 
using UnityEngine.UI;
// few public fields that represent the ui textboxes e.g
public Text name;
// user will now be
string user = name.text;

You can pass now pass these variables as arguments to your register class, or put it all in the same class. 您现在可以将这些变量作为参数传递给您的寄存器类,或将它们全部放在同一类中。 your choice. 你的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM