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

我正在尝试在 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);

 }


叮当猫咪
浏览 262回答 1
1回答

DIEA

问题在于Response该类是在脚本中声明或嵌套的NetworkConnection,因此其他脚本无法直接访问它:public class NetworkConnection : MonoBehaviour{&nbsp; &nbsp; &nbsp;.....&nbsp; &nbsp; [Serializable]&nbsp; &nbsp; public class Response&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; .....&nbsp; &nbsp; }}尝试使用它时,您有两个选择:1.Response尝试引用时提供类所在的类Response。在这种情况下,这就是NetworkConnection类。所以改变s_NetworkConnection.CreateUser(userNameInput.text, emailInput.text,&nbsp; &nbsp; passwordInput.text, delegate (Response response){&nbsp; &nbsp; textInput.text = response.message;});到textInput.text = "Loading...";s_NetworkConnection.CreateUser(userNameInput.text, emailInput.text,&nbsp; &nbsp; passwordInput.text, delegate (NetworkConnection.Response response){&nbsp; &nbsp; textInput.text = response.message;});注意它前面的ResponsenowNetworkConnection.是怎样的。2 .另一种选择是将Response班级移到班级之外NetworkConnection。这应该可以直接从其他脚本访问它。改变public class NetworkConnection : MonoBehaviour{&nbsp; &nbsp; .....&nbsp; &nbsp; [Serializable]&nbsp; &nbsp; public class Response&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; .....&nbsp; &nbsp; }}到public class NetworkConnection : MonoBehaviour{&nbsp; &nbsp; .....}[Serializable]public class Response{&nbsp; &nbsp; .....}
打开App,查看更多内容
随时随地看视频慕课网APP