- Home /
Loading files in background
Here is my problem! I have a script, which download a files via WWW from game server! It could be 5 Mb or more, and there could be 6 - 10 files like this! So, to download all this files from server, it will take a time! My question is how to run script, which is downloading this files, between scenes (in background) to make user go through scenes without interrupt downloading in background?
Answer by goo-muffin · Jan 18, 2014 at 12:26 PM
just create a new GameObject that has the download script on it and add the following function to the script:
function Awake()
{
DontDestroyOnLoad(gameObject);
}
Answer by Fabkins · Jan 18, 2014 at 12:48 PM
The following is a good example of what you need taken from this thread.
float progress = 0.0f;
void IEnumerator Start() {
WWW myW = new WWW( url );
while( !myW.isDone )
{
progress = myW.progress;
yield return null;
}
progress = 1.0f;
}
That example has progress which is cool
Forgot to add the mechanics of this is that you dont need to kick off the WWW download and wait using yield for it complete. You can just kick off the WWW download and keep checking for it to complete.