Hi.
I have a PHP function which returns XML data. I am using C# Unity to retrieve the data to a string variable. I have done this.
In class Requestwww
I have
public static text;
public IEnumerator WaitForRequest(WWW www)
{
yield return www;
// check for errors
if (www.error == null)
{ //Here I store result in a global variable
text=www.text;
Debug.Log("WWW Ok!: " + text);
}
else
{
Debug.Log("WWW Error: " + www.error);
}
}
public IEnumerator getxml(string url )
{
WWW www = new WWW(url);
if (www == null)
{
Debug.Log("www is null");
}
else {
Debug.Log("www is not null");
}
yield return StartCoroutine(WaitForRequest(www));
Debug.Log("xmltext here" + text);
}
And in another class, I call getxml() to start the wwwrequest
Request wwwcall = gameObject.AddComponent<Requestwww>();
StartCoroutine(wwwcall.getxml("http://com.example/something.php")
//Here I tried to access the xmltext variable in Requestwww class
Debug.Log("retrived var"+Requestwww.text)
//But text seems tobe null
But it looks like, the variable Requestwww.text is always null when retried from another class. I don’t get it. I called the Coroutine, wait for result, and then update the global varibale, but it seems like the moment I called it from another class, it has not been updated. What should I do? It has taken me a day aching for an answer…