为了账号安全,请及时绑定邮箱和手机立即绑定

Unity3D - 我无法制作帐户创建系统

Unity3D - 我无法制作帐户创建系统

C#
叮当猫咪 2021-10-31 20:53:59
我正在尝试在 Unity 中创建帐户创建系统,但遇到以下错误:错误 CS0246:找不到类型或命名空间名称响应。您是否缺少程序集参考?脚本网络连接:public void CreateUser(string userName , string email , string pass , Action<Response> response){     StartCoroutine (Make_CreateUser (userName, email, pass, response)); } private IEnumerator Make_CreateUser(string userName , string email , string pass , Action<Response> response){     WWWForm form = new WWWForm ();     form.AddField ("userName", userName);     form.AddField ("email", email);     form.AddField ("pass", pass);     WWW w = new WWW ("http://localhost/game/createUser.php", form);     yield return w;     response (JsonUtility.FromJson<Response> (w.text)); } [Serializable] public class Response {     public bool done       = false;     public string message = ""; }菜单控制器脚本:[SerializeField] private InputField userNameInput     = null; [SerializeField] private InputField emailInput         = null; [SerializeField] private InputField passwordInput     = null; [SerializeField] private InputField RepasswordInput     = null; [SerializeField] private Text textInput             = null; private NetworkConnection s_NetworkConnection =  null; public GameObject Register; private void Awake(){     s_NetworkConnection = GameObject.FindObjectOfType<NetworkConnection> (); } public void SubmitRegister(){     if (userNameInput.text == "" || emailInput.text == "" || passwordInput.text == "" || RepasswordInput.text == "") {         textInput.text = "Please, complete all fields";         return;     }     if (passwordInput.text == RepasswordInput.text) {         textInput.text = "Loading...";         s_NetworkConnection.CreateUser (userNameInput.text, emailInput.text, passwordInput.text, delegate (Response response) {             textInput.text = response.message;         });     } else {         textInput.text = "Passwords are not equals";     } } public void OnMouseDown () {     Register.SetActive (!Register.activeSelf); }
查看完整描述

1 回答

?
DIEA

TA贡献1820条经验 获得超2个赞

问题在于Response该类是在脚本中声明或嵌套的NetworkConnection,因此其他脚本无法直接访问它:


public class NetworkConnection : MonoBehaviour

{

     .....


    [Serializable]

    public class Response

    {

        .....

    }

}

尝试使用它时,您有两个选择:


1.Response尝试引用时提供类所在的类Response。在这种情况下,这就是NetworkConnection类。


所以改变


s_NetworkConnection.CreateUser(userNameInput.text, emailInput.text,

    passwordInput.text, delegate (Response response)

{

    textInput.text = response.message;

});


textInput.text = "Loading...";

s_NetworkConnection.CreateUser(userNameInput.text, emailInput.text,

    passwordInput.text, delegate (NetworkConnection.Response response)

{

    textInput.text = response.message;

});

注意它前面的ResponsenowNetworkConnection.是怎样的。


2 .另一种选择是将Response班级移到班级之外NetworkConnection。这应该可以直接从其他脚本访问它。


改变


public class NetworkConnection : MonoBehaviour

{

    .....


    [Serializable]

    public class Response

    {

        .....

    }

}


public class NetworkConnection : MonoBehaviour

{

    .....

}


[Serializable]

public class Response

{

    .....

}


查看完整回答
反对 回复 2021-10-31
  • 1 回答
  • 0 关注
  • 261 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信