I have code like this:
function getScroll() {
var w = WWW("http://some.url.com/chicken.txt");
yield(w);
}
...
getScroll();
some_stuff();
This code is asynchronous – some_stuff() gets executed before the web page has been retrieved. What I’d like is to make the WWW call synchronous, so that some_stuff() gets executed only after the contents of getScroll() have completely finished.
I found some C# code that uses co-routines, but I don’t speak C# and I can’t translate it into Unityscript. I have a crappy Unityscript solution, which is the following:
function getScroll() {
var w = WWW("http://some.url.com/chicken.txt");
while (!w.isDone) {
WaitForSeconds(1.0);
}
}
...
getScroll();
some_stuff();
But inside the while loop, it’s not actually waiting 1 second – it’s just cycling through as fast as it can, not relinquishing the thread. Can someone tell me how to create the functionality I’m looking for in Unityscript?