【发布时间】:2018-12-24 18:06:39
【问题描述】:
我被这个问题困扰了 3 天,我做了很多研究,但找不到任何答案,这里是正在发生的事情的简要说明,尝试使用 Firebase 数据库和使用 Unity3D 进行身份验证,这里步骤是:
第一个用户登录,如果成功,它将从数据库中获取用户的数据,然后应该停用身份验证面板并激活用户面板。
尝试 SetActive 面板时出现此错误。
SetActive 只能从主线程调用。 加载场景时,构造函数和字段初始化程序将从加载线程中执行。 不要在构造函数或字段初始化程序中使用此函数,而是将初始化代码移至 Awake 或 Start 函数。 UnityEngine.GameObject:SetActive(Boolean)
public void SignInWithEmail()
{
auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
DatabaseReference.GetValueAsync().ContinueWith(task => {
//here after successful signing in, it gets the data from the Database
//and after that it should activate the user panel
//and deactivate the authentication panel
//HERE IS THE PROBLEM
userPanel.SetActive(true);
authPanel.SetActive(false);
}
}
}
我没有尝试加载另一个场景或其他任何内容。
如果需要,我可以提供更多信息
【问题讨论】:
-
UI 元素只能在 UI 线程中修改,你是在另一个线程中调用 SetActive。
-
@Luis 那么如何在主线程中调用它呢? (我没有使用任何线程)