- Home /
Duplicate Question
coroutine not downloading data in Update()
I've written a coroutine that fetches a text file with a number of url's in them to images and then goes about downloading those images and puts them in a texture2d array. This works fine if i call on the coroutine in Start(), however what i want the coroutine to do is download the first image in the list (of urls) in Start() and then depending on user interaction i want to download each next image in the list, this user interaction is registered in Update(), but if the coroutine is called upon in Update() nothing happens, no data is transferred at all... Could anyone help me out here? I'd be grateful for it.
Its quite a lot of code, but lots of it unrelated to the problem in this function. All the rest is for creating puzzle tiles out of a single image so i left that all out. Anyway i just tested this as written down below and again it works if called upon in Start(), but not Update().
So i want to call on this coroutine in update, so that i can download a new image in the list based on user interaction.
So here it goes:
public IEnumerator loadPuzzleTiles_index(int puzzelNR)
{
// download list url's puzzle images
yield return puzzleTiles_index_www;
// download image in list
if (puzzleTiles_index_www.isDone)
{
puzzleTiles_indexList = puzzleTiles_index_www.text;
puzzleTiles_indexArr = puzzleTiles_indexList.Split('\n');
puzzleTiles_puzzleIndex_www = new WWW[puzzleTiles_indexArr.Length];
puzzleTiles_puzzleIndex_texture = new Texture2D[1];
puzzleTiles_puzzleIndex_texture[0] = new Texture2D(832,664,TextureFormat.ARGB32,false);
puzzleTiles_puzzleIndex_www[puzzelNR] = new WWW(puzzleTiles_indexArr[puzzelNR]);
yield return puzzleTiles_puzzleIndex_www[puzzelNR];
if (puzzleTiles_puzzleIndex_www[puzzelNR].isDone)
{
puzzleTiles_puzzleIndex_texture[0] = puzzleTiles_puzzleIndex_www[puzzelNR].texture;
}
}
}
something went wrong with copying the text, so i did post the function again properly above.
This is a duplicate of your other question:
http://answers.unity3d.com/questions/619339/downloading-data-via-coroutine-in-update.html