我正在尝试根据发生的错误类型显示错误消息。为此,我有一个公共变量“errorMessage”,它附加到检查器中的 UI 文本。我可以在 start 函数中更改文本值,但似乎无法在 GetErrorMessage 函数中更改该值。以下是代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Firebase.Auth;
using System;
public class LoginController : MonoBehaviour
{
public InputField email, password;
public Screen nextScreen;
public Text errorMessage;
void Start()
{
password.inputType = InputField.InputType.Password;
errorMessage.text = "This is error"; //this works
}
public void Login()
{
//login code which calls GetErrorMessage(error)
}
void GetErrorMessage(string error)
{
print("error function called");
print(error);
print(errorMessage.text); //works till here
errorMessage.text = error; //doesn't work from here. Seems like it stops functioning.
print(error); //and this never gets printed
}
}