I am creating a simple 3D model viewing application. The models are loaded at run-time from a text file located on a server that the user can point to. Loading and creation of the meshes works fine, as do texturing, navigation etc. I have but one, simple problem…
A text file of approximately 1mb takes a little while to load, given the slow speed of the Edge network. It is slightly better over WiFi. I would like to show the loading and model-building progress as GUIText, so the user doesn’t sit there like an idiot not knowing what’s going on.
HERE IS THE PROBLEM: My GUIText object created for this purpose does not update when I call myGUITextObject.text = someNewText in either the ReadModelFileFromWeb or CreateModelInUnity methods.
The pseudo-code of this is as follows:
Update()
{
if(isLoading)
{
ReadModelFileFromWeb();
CreateModelInUnity();
}
}
void ReadModelFileFromWeb()
{
//some loading code here...
//progress updating code...
while(!myWWW.isDone)
{
myGUIText.text = myWWW.progress //myGUIText object doesn't update
}
}
void CreateModelInUnity()
{
//some model creation code here...
//progress updating code
myGUIText.text = numVertsLoaded.ToString() + " vertices loaded..."; //myGUIText object doesn't update
}
I’ve tried making the ReadModelFileFromWeb and CreateModelInUnity methods coroutines and yielding for fixed update etc…, but that doesn’t allow updating of the GUIText either. I know the GUIText works as I have other scripts that are updating it in the game, and the last update that I call in the above methods does actually change the text. It just doesn’t work during the execution of the above methods. I’m sure this has something to do with intertwined update methods, but I can’t figure it out.
Any examples of this behavior working in others’ work or suggestions are greatly appreciated.