Unity3D - I can't make account creation system

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Unity3D - I can't make account creation system



I'm trying to create an account creation system within Unity, but I run into the following error:



error CS0246: The type or namespace name Response could not be found. Are you missing an assembly reference?



Script NetworkConnection:


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 = "";
}



MenuController script:


[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);
}



The problem is in the MenuController script in this snippet:



s_NetworkConnection.CreateUser (userNameInput.text, emailInput.text, passwordInput.text, delegate (Response response) {




1 Answer
1



The problem is that the Response class is declared or nested inside the NetworkConnection script making it directly inaccessible from other scripts:


Response


NetworkConnection


public class NetworkConnection : MonoBehaviour
{
.....

[Serializable]
public class Response
{
.....
}
}



You have two options when trying to use it:



1.Provide the class that the Responseclass is inside when trying to reference Response. In this case that's the NetworkConnection class.


Response


Response


NetworkConnection



So change


s_NetworkConnection.CreateUser(userNameInput.text, emailInput.text,
passwordInput.text, delegate (Response response)
{
textInput.text = response.message;
});



to


textInput.text = "Loading...";
s_NetworkConnection.CreateUser(userNameInput.text, emailInput.text,
passwordInput.text, delegate (NetworkConnection.Response response)
{
textInput.text = response.message;
});



Notice how Response now has NetworkConnection. in front of it.


Response


NetworkConnection.



2.Another option is just to move the Response class outside the NetworkConnection class. That should make it accessible directly from other scripts.


Response


NetworkConnection



Change


public class NetworkConnection : MonoBehaviour
{
.....

[Serializable]
public class Response
{
.....
}
}



to


public class NetworkConnection : MonoBehaviour
{
.....
}

[Serializable]
public class Response
{
.....
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions