Android : WWW class does not work in unity

on Tuesday, April 14, 2015


First of all. Im new to Unity and im developing in the new Unity 5.0.0. I´ve been looking at the WWW class in Unity documentation and followed through it and havent got it to work yet. I have looked in other questions and googled alot and couldnt get it to work. This is the code I got in my 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 my main file where I want to call the string getTemp method and show the data in a label.. it doesnt work. Nothing shows up and im struggling to figure it out (Im trying to show the data in the label as a text (string).



public class main : MonoBehaviour {

apiManager myApiManager = new apiManager();

void OnGUI() {

GUI.Label(ScreenPosition(0, 500, 300,300), myApiManager.getTemp());

}
}


Is it something im missing or what? Can you please provide me information on how it should work or if I have missed something? Thanks.


0 comments:

Post a Comment