I am trying to create a new account using the parse api with Unity and running into all kinds of trouble. All I would like to do is create a account on parse. Then on success load a scene.
This is the code used to create a new account.
bool success = true;
string error;
try
{
Task signup = user.SignUpAsync().ContinueWith(t =>
{
if (t.IsFaulted || t.IsCanceled)
{
success = false;
}
});
}
catch (System.Exception e)
{
error = "Failed to sign up Parse User. Reason: " + e.Message;
success = false;
}
if(success)
Application.LoadLevel("ExampleScene");
I wont post all the things I have tried because I have tried a lot of things.
The main problems that always occur:
So what it boils down to is that I cannot figure out how to wait for the task to finish without disabling all Unity functionality.
How am I supposed to go about creating a parse account and getting notified when it is finished and then call Unity functions again?
You can yield your Task like this for this case:
private IEnumerator SignUpHandler()
{
bool success = true;
string error;
Task signup = user.SignUpAsync();//.ContinueWith(t =>
while (!signup.IsCompleted) yield return null;
if (signup.IsFaulted || signup.IsCanceled)
{
//Debug.Log("Error " + signup.Exception.Message);
error = "Failed to sign up Parse User. Reason: " + signup.Exception.Message;
success = false;
}
else
{
Debug.Log("Done");
Application.LoadLevel("ExampleScene");
}
}
and call your SignUpHandler from somewhere like this: StartCoroutine("SignUpHandler");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.