Started creating a leaderboard

This commit is contained in:
Anthony Berg
2020-10-05 23:27:16 +01:00
parent 1e0fb19fe0
commit c1d5de61a8
10 changed files with 1236 additions and 111 deletions

View File

@@ -21,6 +21,8 @@ public class Login : MonoBehaviour
public TMP_InputField username; //This is for the username text input.
public TMP_InputField password; //This is for the password text input.
public Button login; //This is the button used to log in.
public GameObject errors;
public TextMeshProUGUI errorsText;
private bool CheckIsEmpty() //This checks if the strings are empty.
{
@@ -85,8 +87,17 @@ public class Login : MonoBehaviour
else
{
string status = www.downloadHandler.text; //This downloads the data from the server.
LoginInformation information = JsonConvert.DeserializeObject<LoginInformation>(status); //This deserializes the JSON string to a class.
Debug.Log(status);
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
};
LoginInformation information = JsonConvert.DeserializeObject<LoginInformation>(status, settings); //This deserializes the JSON string to a class.
if (information.errors != null)
{
errors.SetActive(true);
errorsText.text = information.errors;
}
if (information.success) //If the user has successfully logged in.
{

View File

@@ -1,8 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using UnityEditor;
using UnityEngine.Networking;
public class Property
@@ -778,6 +780,31 @@ public class Player
public void Pay(float fee) //This function makes the user pay.
{
money -= Convert.ToInt32(fee); //This deducts the money from the user's balance.
if (fee > 0)
{
StartCoroutine(UpdateTable);
}
}
IEnumerable UpdateTable()
{
List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
//POST Data
formData.Add(new MultipartFormDataSection("id", UserManager.userID.ToString())); //For the username.
formData.Add(new MultipartFormDataSection("money", "200")); //For the email.
UnityWebRequest www = UnityWebRequest.Post(Domain.subDomain("includes/updatespent.inc.php"), formData); //This initiates the post request.
yield return www.SendWebRequest(); //This sends the post request.
if (www.isNetworkError || www.isHttpError) //This checks for an error with the server.
{
Debug.Log(www.error); //This prints the error.
}
else
{
Debug.Log(www.downloadHandler.text); //This sends the error code or if it worked on the server side.
}
}
public bool Mortgage(int currentProperty) //This is used for mortgaging a property.