Hello everyone, I’ve came across an issue to where I have lets say 20 Images That need to be changed on the fly. Now My problem is that unity is running this
Here’s the for loop I use for grabbing the pictures.
for(int c = 0; c < 20;)
{
if(Application.isEditor)
{
WWW www = new WWW("file:///"+Application.dataPath+"/PowerPoints/BOP/Annular/Annular ("+(c+1)+").png");
StartCoroutine(FindFile(a,b,c,www));
if(isdone)
{
c+=1;
isdone = false;
}
}
and here’s the code thats putting the pictures in there proper place
You should just start a coroutine in your Start method and do your processing inside. After processing all textures, you can set some variable which might later be used e.g. inside Update method. Pseudocode:
bool _imagesLoaded = false;
void Start()
{
StartCoroutine(LoadFiles());
}
IEnumerator LoadFiles()
{
for(...)
{
WWW www = new WWW(...);
yield return www;
// here, www call finished, so you can retrieve texture and process it
}
_imagesLoaded = true;
}
void Update()
{
if(_imagesLoaded)
{
// do something
}
}
I suggest reading a bit more about coroutines at Unity Gems, and also to look at Unity Answers for some examples of using WWW.
the yield return StartCoroutine prevents the for loop from loading FindFile too Fast, cause it seemed that speed was an issue and was trying to have it wait enough for it to show on the screen. Only problem is that framerate is a little bit slow at some points but not complaining, if threads could work for this this piece of code would be perfect for downloading. Thanks everyone for helping
this is where you should use threads.
it’s complicated and i’m not the man to tell you how to do that but basically thread should allow you to download images in one thread and keep unity doing something else in the same time.(for example showing progress bar or something…)