[英]How to load level after user sign up in parse.com and unity3d?
用戶注冊后,我需要加載下一個級別,但無法正常工作。 我不斷收到“只能從主線程調用StartCoroutine_Auto”錯誤。 當我嘗試使用LoadLevel()方法而不是startcoroutine方法時,我也收到“只能從主線程調用LoadLevelAsync”錯誤。 我究竟做錯了什么? 以及解決方法(此問題的示例解決方案是超級解決方案)。 謝謝,麻煩您了。
void Start ()
{
detectDevice();
if(ParseUser.CurrentUser == null)
{
hasError = false;
SignInPanel.SetActive(true);
errorMessage = "";
HeaderText.text = "A warm welcome to you!!!\nWhat shall we call you ?";
registrationSuccessful = false;
}
else if(ParseUser.CurrentUser != null)
{
Application.LoadLevel(nextLevel);
}
}
// Update is called once per frame
void Update ()
{
ParseUser currentUser = ParseUser.CurrentUser;
Debug.Log (currentUser["deviceType"]);
if(hasError)
{
HeaderText.text = errorMessage;
}
else if(!hasError)
{
HeaderText.text = "A warm welcome to you!!!\nWhat shall we call you ?";
}
else if(registrationSuccessful)
{
HeaderText.text =" success";
}
}
public void registerNewParseUser ()
{
int randomNumber = Random.Range(1, 1000);
string myUsername = usernameField.text;
string myPassword = myUsername + randomNumber;
ParseUser newUser = new ParseUser();
newUser.Username = myUsername;
newUser.Password = myPassword;
newUser["currentLevel"] = "1";
newUser["RemainingLives"] = 5;
newUser["deviceType"] = deviceTypeString;
Debug.Log ("Registering User....");
try
{
newUser.SignUpAsync().ContinueWith(t =>
{
if (t.IsFaulted)
{
foreach(var e in t.Exception.InnerExceptions)
{
hasError = true;
ParseException parseException = (ParseException) e;
// string that displays the error to the user
errorMessage = "Error: "+parseException.Message;
}
}
else
{
// Login was successful.
Debug.Log("Registration was successful!");
registrationSuccessful = true;
StartCoroutine(WaitAndLoad());
}
});
}
catch (System.Exception error)
{
Debug.Log (error.Message);
}
}
IEnumerator WaitAndLoad()
{
registrationSuccessful = true;
yield return new WaitForSeconds(2);
LoadLevel();
}
void LoadLevel ()
{
Application.LoadLevel(1);
}
}
我找到了解決自己問題的方法。 我只是將Update()中的else else if(registrationSuccessful){....}語句更改為它自己的單獨的if(){....}語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.