- Home /
Question by
NabHMa · May 15, 2021 at 01:49 PM ·
scripting problemunityeditorwebrequestscriptable object
Get data from Server
Hello everyone , I want to get different texts from server to Unity Text Mesh Pro component and the script works well and I can get for example 1 Text but I didn't know how to manage the script for different texts. this is the script.
public class GetMethod : MonoBehaviour { public TextMeshProUGUI getText; public TextMeshProUGUI getText1;
string getURL = "https://myserver/text.txt";
string getURL2 = "https://myserver/text1.txt";
public string GetURL2 { get => getURL2; set => getURL2 = value; }
public void GetText()
{
StartCoroutine(GetTheText());
}
IEnumerator GetTheText()
{
string URL = getURL;
UnityWebRequest www = UnityWebRequest.Get(URL);
yield return www.SendWebRequest();
getText.text = www.downloadHandler.text;
string URL = getURL2;
UnityWebRequest www = UnityWebRequest.Get(URL);
yield return www.SendWebRequest();
getText1.text = www.downloadHandler.text;
}
so it looks like that but I know for getURL2 does not work so anyone can help me please ,,how to call other texts
Comment
One thing, you cannot declare URL a second time in the same scope.
string URL = getURL2; //don't declare it
URL = getURL2; //just reuse it