- Home /
Question by
abssuper20 · Jul 13, 2020 at 06:26 AM ·
unity 5textdatabase
Can't set unity text fields with data retrieved from FireBase.
So my current goal is to retrieve values from FireBase and update text fields in Unity based on their values. The problem is it retrieves and sets only 1 text field out of 5 and stops execution for some reason. I put a Debug statement to confirm the amount of data being retrieved and its retrieving the complete data required . Any idea why is this happening? For testing purposes i tried populating a string type list with the values retrieved from FireBase and the list is storing the values properly without any issue. Here is my code
public class FirebaseManager : MonoBehaviour
{
public static FirebaseManager instance;
private DatabaseReference myDB;
public Text[] bootAmountText;
private void Awake()
{
instance = this;
// Set up the Editor before calling into the realtime database.
FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://teenpatti-1fbb9.firebaseio.com/");
// Get the root reference location of the database.
myDB = FirebaseDatabase.DefaultInstance.RootReference;
SetBootAmounts();
}
public void SetBootAmounts()
{
myDB.GetValueAsync().ContinueWith(task =>
{
if (task.IsFaulted)
{
// Handle the error...
Debug.Log("No data found");
}
else if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
int counter = 0;
var bootAmounts = snapshot.Child("BootAmount").Children;
foreach(var data in bootAmounts)
{
Debug.Log(data.Value);
bootAmountText[counter].text = data.Value.ToString();
counter++;
}
}
});
}
}
Comment