Question

I am making a game that load a level by reading XML. That part works fine but I can't load Textrues. He doesnt give a error or something like that. There is just no textrue, it's a null object.

this is the code that read the xml:

void ReadXML(){

    XmlDocument doc = new XmlDocument();
    doc.Load("world/world.xml");

    //load all textrues
    XmlNodeList elemList = doc.GetElementsByTagName("textrue");
    _matrial = new Texture[elemList.Count];
    for (int i=0; i < elemList.Count; i++){
        LoadTexture(elemList[i].InnerXml);
        _matrial[i] = loaded;
        //_matrial[i] = Resources.Load(elemList[i].InnerXml) as Texture;
        Debug.Log(_matrial[i] + " <> " + elemList[i].InnerXml);
    }


    ///.... here he loads al object, that works fine

}

This is the LoadTexture methode:

IEnumerator LoadTexture(string url) {
    WWW www = new WWW(url);
    yield return www;
    loaded = www.texture;
}

Thank you!

Was it helpful?

Solution

It has to wait until the textare is loaded before I could use it. So the function should looks like this:

IEnumerator LoadTexture(string url) {
    WWW www = new WWW(url);
    while (!www.isDone){
        yield return null;
    }
    loaded = www.texture;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top