c# - WWW class does not work in unity -


first of all, i'm new unity , i'm developing in new unity 5.0.0. i´ve been looking @ www class in unity documentation , followed through , haven't gotten work yet. have looked in other questions , googled lot , couldn't work. code got in apimanager:

using unityengine; using system.collections;  public class apimanager : monobehaviour  {  public string url = "url";   public string temp;   public void start(){      www w = new www (url);      startcoroutine (waitforrequest (w));   }  ienumerator waitforrequest(www w){      yield return w;      temp = w.text.tostring ();  }  public string gettemp(){      return temp;  }  } 

and in main file want call string gettemp method , show data in label doesn't work. nothing shows , i'm struggling figure out. (i'm trying show data in label text (string).)

public class main : monobehaviour {  apimanager myapimanager = new apimanager();  void ongui() {  gui.label(screenposition(0, 500, 300,300), myapimanager.gettemp());  } } 

can please provide me information on how should work or if have missed something? thanks.

the issue creating www object outside of coroutine method. move within waitforrequest:

    using unityengine; using system.collections;  public class apimanager : monobehaviour  {  public string url = "url";   public string temp;   public void start(){      startcoroutine (waitforrequest (w));  }   ienumerator waitforrequest(){      www w = new www (url);      yield return w;      temp = w.text.tostring ();  }  public string gettemp(){      return temp;  }  } 

also should not creating monobehavior object within main monobehavior. instead define public property , assign within editor (you can use findobjectoftype @ runtime):

    public class main : monobehaviour {  public apimanager myapimanager;   void ongui() {  gui.label(screenposition(0, 500, 300,300), myapimanager.gettemp());  } } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -