- Home /
How to Save data as transactions in C# using firebase?
I’m making an quiz game in unity using firebase realtime database. I want to save on firebase what players have answered each questions, and later show to player what others also have answered
Example: Is sky blue? Yes or No
82% has answered Yes
12% has answered No
Firebase doc is using leaderboard setup, that i didn’t understand. Here is the link to firebase doc
I have been struggling with this for many days now. Here is my code that work, but i don’t know how to add all other questions.
private void AddCount(DatabaseReference clickCountRef)
{
clickCountRef.RunTransaction(mutableData =>
{
List<object> counts = mutableData.Value as List<object>;
if (counts == null)
{
counts = new List<object>();
return TransactionResult.Success(mutableData);
}
yesFromFirebase = (long)((Dictionary<string, object>)counts[0])["yes"];
noFromFirebase = (long)((Dictionary<string, object>)counts[0])["no"];
Dictionary<string, object> newCounter =
new Dictionary<string, object>();
newCounter["yes"] = yesFromFirebase + yesFB;
newCounter["no"] = noFromFirebase + noFB;
counts[0] = (newCounter);
mutableData.Value = counts;
yesFB = 0;
noFB = 0;
return TransactionResult.Success(mutableData);
});
}
Answer by dougthompson · May 16, 2020 at 12:20 PM
have you had a look at https://willhart.io/firebase-and-unity-part-2/
Your answer
Follow this Question
Related Questions
PUN - Choose random Hero for player 0 Answers
How would you spawn UI GameObjects inside a grid in multiplayer? 2 Answers
Multiple Cars not working 1 Answer
Multiplayer servers for free 1 Answer
Distribute terrain in zones 3 Answers