I want to get the result of a webrequest in another function but unfortunately the variable of the webrequest stays empty, because the webrequest isn't already xecuted when I call the variable. I call the OpenFile Function which calls the GetText one:
private string[] m_fileContent;
public void OpenFile(string filePath)
{
StartCoroutine(GetText());
Console.Log(m_fileContent);// is empty
}
IEnumerator GetText()
{
UnityWebRequest www = UnityWebRequest.Get("http://...");
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
m_fileContent = www.downloadHandler.text.Split('\n');
Debug.Log("here" + m_fileContent);//data printed ok
}
}
So the GetText function prints the text but in the OpenFile function the variable m_fileContent is empty.
Any ideas how to solve this?
Thank you!