- Home /
problem updating info to data base
Hi, I'm using "Rest Client for unity" which I imported from the asset store. I have a problem which I mange to update the data but! the update is done regardless of the user info. ill explain I want to add to the user with a name he typed down 2 gems, however with the code I wrote the player get 2 gems every time he press down "update", but he starts from 0 every time I initialize the game.
the code I wrote doesn't access the info on the player in the data base.
my code:
using Proyecto26; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class gameManagerServer : MonoBehaviour { public static string username; public static int gems; public InputField name2 ;
user user1 = new user();
public void onClickUpdate()
{
username = name2.text.ToString();
RetrieveFromDataBase();
user1 = new user();
if (username != "") // nessecery, otherwise can delete all data.
{
RestClient.Put("https://save-the-space.firebaseio.com/" + username + ".json", user1);
}
else
{
Debug.Log("cannot update user with emepty username");
}
}
private void RetrieveFromDataBase()
{
RestClient.Get<user>("https://save-the-space.firebaseio.com/" + username + ".json").Then(response =>
{
user1 = response;
Debug.Log(user1);
// user1.gems = response.gems;
// user1.username = response.username;
upadteScore();
});
}
private void upadteScore()
{
// gems = user1.gems;
gems++;
gems++;
Debug.Log(gems);
}
}
Your answer
Follow this Question
Related Questions
How to fix lost data when i update the apk 0 Answers
Why PlayerPrefs not working although I use "HasKey" and Save() on android? 0 Answers
Saving to a database 1 Answer
How do I go about using a server to store and retrieve data? 0 Answers
Can I download and then read a CSV all at runtime? If so, how? 1 Answer