Created
September 25, 2019 04:45
-
-
Save stickylabdev/15e2c0f962ef61f15ced69e438b44aa3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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