Skip to content

Instantly share code, notes, and snippets.

@stickylabdev
Created September 25, 2019 04:45
Show Gist options
  • Save stickylabdev/15e2c0f962ef61f15ced69e438b44aa3 to your computer and use it in GitHub Desktop.
Save stickylabdev/15e2c0f962ef61f15ced69e438b44aa3 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using Proyecto26;
using UnityEngine;
using UnityEngine.UI;
public class PlayerScores : MonoBehaviour {
public Text scoreText;
public InputField nameText;
private System.Random random = new System.Random ();
User user = new User ();
public static int playerScore;
public static string playerName;
// Start is called before the first frame update
private void Start () {
playerScore = random.Next (0, 101);
scoreText.text = "Score: " + playerScore;
}
public void OnSubmit () {
playerName = nameText.text;
PostToDatabase ();
}
public void OnGetScore () {
RetrieveFromDatabase ();
}
private void UpdateScore () {
scoreText.text = "Score: " + user.userScore;
}
private void PostToDatabase () {
User user = new User ();
RestClient.Put ("https://stickman-pubg.firebaseio.com/" + playerName + ".json", user);
}
private void RetrieveFromDatabase () {
RestClient.Get<User> ("https://stickman-pubg.firebaseio.com/" + nameText.text + ".json").Then (response => {
user = response;
UpdateScore ();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment