Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using System.Collections.Generic;
public class ranking : MonoBehaviour {
void Start() {
//StartCoroutine(GetPlayers()); // Zaczyna czytanie rangingu
//StartCoroutine(SetPlayer("testy_28",28)); // Dodaje do rankingu gracza o nicku "testy_28" i wyniku 28
}
[System.Serializable]
public struct playerObject
{
public string nick;
public int wynik;
}
[System.Serializable]
public class playersData
{
public List<playerObject> players;
}
IEnumerator GetPlayers() {
UnityWebRequest www = UnityWebRequest.Get("https://niepolecam.cba.pl/ranking.php?state=download");
yield return www.Send();
if(www.isNetworkError) {
Debug.Log(www.error);
}
else {
playersData data = JsonUtility.FromJson<playersData>(www.downloadHandler.text);
foreach (playerObject p in data.players) { //tu sa gracze wczytani z rankingu
print (p.nick + " : " + p.wynik);
}
}
}
IEnumerator SetPlayer(string nick, int wynik) {
UnityWebRequest www = UnityWebRequest.Get("https://niepolecam.cba.pl/ranking.php?state=upload&wynik="+wynik.ToString() +"&nick="+nick);
yield return www.Send();
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more