x


How to access StartCoroutine in a static way

Hello, I got this small problem. I am using StartCoroutine for a www request but I can't figure a work-around to access it in a static way. Here is a sample code of what I do:

public static void mysql_query(string sServer, string sQuery)
    {
        sQuery = WWW.EscapeURL(sQuery);
        www = new WWW(sServer+"?Query="+sQuery);
        StartCoroutine(WaitForRequest(www));
        if(www.error == null)
        {
            ResultSet = www.text;
        }
        else
        {
            Debug.Log("Error at: "+ www.error);
        }
    }

My problem is that StartCoroutine is obviously a non static method. I can't seem to figure out a work-around to access it in a none static way.

more ▼

asked Oct 29 '10 at 10:56 PM

Extremo gravatar image

Extremo
26 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Just give it a dummy gameobject to run on. Maybe put a script on that gameobject that gives you singleton-style access to it. You should then be able to do something like dummyComponent.StartCoroutine( whatever );

more ▼

answered Oct 29 '10 at 11:17 PM

Tetrad gravatar image

Tetrad
7.3k 27 37 89

that seems a very inelegant and roundabout way of doing it

Apr 15 '12 at 10:39 PM ina

you said "roundabout"

Jul 10 '12 at 02:29 PM Cawas

@cawas: This comment is pretty useless... Do you want to point out "roundabout (indirect)" isn't a proper word in this case?

Jul 10 '12 at 02:45 PM Bunny83

@bunny83 finally unity team let me comment again (many migration issues with UDN I had)! nope, it's just useless indeed. shouldn't bother you so much, tho. you could say something funny back instead. ;-)

Jul 23 '12 at 03:10 PM Cawas
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5272
x426
x336
x215

asked: Oct 29 '10 at 10:56 PM

Seen: 2446 times

Last Updated: Jul 23 '12 at 03:10 PM