C 如何使用Firebase auth UNITY3D连续更改游戏对象

C 如何使用Firebase auth UNITY3D连续更改游戏对象,c,firebase,unity3d,firebase-authentication,C,Firebase,Unity3d,Firebase Authentication,为什么我的代码不起作用?我想在身份验证确定或身份验证失败后更改UI状态 Services.Api.Auth.SignInWithEmailAndPasswordAsync(_emailField.text, _passwordField.text).ContinueWith(auth => { if (auth.IsFaulted || auth.IsCanceled) { Services.Loading.Hide();

为什么我的代码不起作用?我想在身份验证确定或身份验证失败后更改UI状态

Services.Api.Auth.SignInWithEmailAndPasswordAsync(_emailField.text, _passwordField.text).ContinueWith(auth =>
    {
        if (auth.IsFaulted || auth.IsCanceled)
        {
            Services.Loading.Hide();
            Services.StateManager.ShowPopUp(Localisation.GetString("warningTitleText"), auth.Exception.Message.ToString());
            Debug.LogFormat("<color=red><b>[WEB]</b></color>" + " AUTHORIZATION FAULTED");
            return;
        }

        Services.Api.User = auth.Result;

        Services.Photon.Connect();
        Services.StateManager.Switch(nextState);

        Debug.LogFormat("<color=red><b>[WEB]</b></color>" + " AUTHORIZATION OK: {0}   ({1})",
            Services.Api.User.DisplayName, Services.Api.User.UserId);
    });


从您提供的小代码中,我的最佳猜测是您正试图从“Services.Api.Auth.signiWithEmailandPasswordAsync”创建的某个随机线程更改“UI状态”。我不太熟悉Unity中的多线程处理,但通常UI只能由拥有它的线程来更改。

而在我的情况下,我可以根据授权是否成功来更改用户界面?我绝对相信有一种方法可以完成您试图做的事,但是你必须在你的主线程上完成它。。。从您提供的小代码来看,很难说发生了什么,而且您没有提供任何异常信息或类似信息……我必须将此异步添加到方法中,并可以等待在主线程中继续:public async void LoginButton_Click(GameObject newState){Services.Loading.Show();wait Services.Api.Auth.signiWithEmailAndPasswordAsync(_emailField.text,_passwordField.text)。ContinueWith(task=>{u taskStatus=task;})。。。
            Services.Loading.Hide();
            Services.StateManager.ShowPopUp(Localisation.GetString("warningTitleText"), auth.Exception.Message.ToString());
        Services.Photon.Connect();
        Services.StateManager.Switch(nextState);