- Home /
Trying to create a static class for WWW-based functions and such
I am trying to make a static class that I can access a number of WWW utility functions without having to manually drag the class, get object, get component, etc, to reference the functions. (I'm still relatively new to static type declarations, so feel free to point out if there is a better way than to use static for this.)
A simple example is like this:
IOdata.js contains a number of static functions such as a function that both fetches data from a URL and parses it before returning the result
static var globalData:String;
static function GetAndParse(url:String){ var w:WWW = WWW(url); yield w; var t:String = w.text; // parse it a bit globalData = t; } static function GetData(){ return globalData; }
It looks like static functions do not get along with www
and yield
... I am not sure how to make the above work!
You can't. Coroutine cannot be launched inside a static class (or a static method). The underlying GameObject is the coroutine scheduler.
There's the singleton method @ http://answers.unity3d.com/questions/173762/when-using-yield-and-www-class-the-function-wont-r.html