c# - Unity3d WWWForm only works from Start() -
c# - Unity3d WWWForm only works from Start() -
i have below code works fine , sends info server required:
ienumerator start () { diffculty d = diffculty.getinstance (); int level = d.getdiffculty (); wwwform form = new wwwform(); form.addfield( "highscore", 1000); form.addfield( "name", stringtoedit); form.addfield( "level", level); www download = new www( url, form ); yield homecoming download; if((!string.isnullorempty(download.error))) { debug.log("error downloading: " + download.error ); } else { debug.log(download.text); dowindow0 = false; } }
however want code trigger on press of button in guiwindow have below code.
ienumerator senddata(){ diffculty d = diffculty.getinstance (); int level = d.getdiffculty (); wwwform form = new wwwform(); form.addfield( "highscore", 1000); form.addfield( "name", stringtoedit); form.addfield( "level", level); www download = new www( url, form ); yield homecoming download; if((!string.isnullorempty(download.error))) { debug.log("error downloading: " + download.error ); } else { debug.log(download.text); dowindow0 = false; } } void dowindow0(int windowid) { stringtoedit = guilayout.textfield (stringtoedit, 25); if (guilayout.button ("submit score")) { senddata(); } } void ongui() { //dowindow0 = gui.toggle(new rect(10, 10, 100, 20), dowindow0, "window 0"); if (dowindow0) gui.window(0, windowrect, dowindow0, ""); }
however when press button ("submit score") nil seems happen , info not received server
it's because you're not calling startcoroutine(senddata()). calling send info have returns ienumerator value required loop through method, startcoroutine uses ienumerator value finish method.
c# unity3d
Comments
Post a Comment