· 7 years ago · Jan 08, 2019, 01:36 AM
1 IEnumerator PostScoresV2(string name, int score, int level)
2 {
3 print("POSTING HIGH SCORE");
4
5 //This connects to a server side php script that will add the name and score to a MySQL DB.
6 // Supply it with a string representing the players name and the players score.
7 string hash = Md5Sum(name + score + level + secretKey);
8
9 string postUrl = addScoreURL + "name=" + UnityWebRequest.EscapeURL(name) + "&score=" + score + "&level=" + level + "&firstSkipped=" + _blittAnalytics.FirstRoundSkipped + "&firstLost=" + _blittAnalytics.FirstRoundLostLife + "&totalBonus=" + _blittAnalytics.TotalBonus + "&totalLaserT1=" + _blittAnalytics.TotalLaser1Towers + "&totalLaserT2=" + _blittAnalytics.TotalLaser2Towers + "&totalIceT1=" + _blittAnalytics.TotalIce1Towers + "&hash=" + hash;
10 print("POST URL: " + postUrl);
11
12 _playerRankContainer.SetActive(true);
13 _playerRankText.text = "LOADING";
14
15
16
17 UnityWebRequest www = UnityWebRequest.Get(postUrl);
18
19 DownloadHandlerBuffer dH = new DownloadHandlerBuffer();
20 www.downloadHandler = dH;
21
22 yield return www.SendWebRequest();
23
24 if(www.isNetworkError || www.isHttpError) {
25 Debug.Log(www.error);
26 }
27 else {
28 // Show results as text
29 Debug.Log(www.downloadHandler.text);
30 print("UNITY WEB REQUEST TEXT : " + www.downloadHandler.text);
31 _playerRankText.text = www.downloadHandler.text;
32 }
33
34 }