Preload an image

In my game an image is loaded using WWW to be used as a texture in a level.
When the level is finished, the same level is reloaded again but another image is loaded using WWW.
What I would like to have is that the new image will be loaded while the level is not finished yet.
So when the level is finished, the new image can be used as a texture directly and you don’t have to wait for downloading.

I want to do that in this way:

function Start()
{	
	//Some code
	image = new WWW ("image" + index + "1.png"); yield image; //index is increasing by 1 everytime
	if (firstTime == 0)
	{
		firstTime = 1;
		Next();
	}
}

function Next()
{
	Image.renderer.material.mainTexture = image.texture;
	//Some other code
	Start();
}

In another script called “gameFinished”, the function Next is called and the new image can be used directly as a texture. At least, that’s the idea.
But of course, I get the error BCE0070: Definition of ‘Start()’ depends on ‘Next()’ whose type could not be resolved because of a cycle.

How can I do this correctly?

Declare the return type for the function, which is IEnumerator since it’s a coroutine. i.e., “function Start () : IEnumerator”. Unity will normally infer the return type automatically, but that’s not possible if you have functions that call each other recursively.

–Eric

It’s working great now.
Thanks!