Store WIP
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
|
||||
public class TimeAliveMoney : MonoBehaviour
|
||||
{
|
||||
@@ -26,10 +27,13 @@ public class TimeAliveMoney : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
float moneyEarned => timeAlive * moneyPerSecond;
|
||||
public void OnPlayerDeath()
|
||||
{
|
||||
totalMoneyEarned += timeAlive * moneyPerSecond;
|
||||
SaveMoney();
|
||||
StartCoroutine(SaveDataToServer((int)moneyEarned));
|
||||
|
||||
timeAlive = 0f;
|
||||
totalMoneyText.text = ((int)totalMoneyEarned).ToString() + "$";
|
||||
}
|
||||
@@ -39,5 +43,24 @@ public class TimeAliveMoney : MonoBehaviour
|
||||
{
|
||||
PlayerPrefs.SetFloat("Money", totalMoneyEarned);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
}
|
||||
|
||||
IEnumerator SaveDataToServer(int _moneyEarned){
|
||||
WWWForm f1 = new WWWForm();
|
||||
f1.AddField("username", DataManager.Username);
|
||||
f1.AddField("total",(int)totalMoneyEarned);
|
||||
|
||||
WWW reqTotal = new WWW(DataManager.API_Endpoint + "set_total.php",f1);
|
||||
yield return reqTotal;
|
||||
|
||||
WWWForm f2 = new WWWForm();
|
||||
f2.AddField("username", DataManager.Username);
|
||||
f2.AddField("best", (int)_moneyEarned);
|
||||
|
||||
WWW reqBest = new WWW(DataManager.API_Endpoint + "set_best.php",f2);
|
||||
yield return reqBest;
|
||||
|
||||
Debug.Log(reqBest.text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user