- Home /
how to get data from server in unity
hi! in my game i have to get some data from my server. i used WWW class to do this. but i don't know to transfer any data from the server we have to generate JSON file or no!!! can anyone help me?? i also write a snippet of code to download some string from server i don't know how to fix it. using UnityEngine; using System.Collections; using LitJson;
public class JSON_D : MonoBehaviour{
public static JSON_D staticOBJ;
public static parseJSON parsejson;
public WWW www;
void Start()
{
staticOBJ = this;
staticOBJ.function();
}
public void function()
{
StartCoroutine(getData());
}
protected IEnumerator getData()
{
string url = "any url in any website. doesn't matter";
//WWW www = new WWW(url);
this.www = new WWW(url);
yield return www;
if (www.error == null)
{
Debug.Log(www.text);
}
else
{
Debug.Log("ERROR: " + www.error);
}
}
and another code exist in server to serve it.
//after retrieving data from database :
echo $names ." ". $record
?>
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612001612im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Videos in WebGL 0 Answers
Creating a user defined ID for firebase realtime database 0 Answers
How do I get list of country name, state name and city name for my users in my Game? 1 Answer