Howdy folks,
I’m very new to Unity, and struggling with the MonoBehaviour object.
The goal is to create an object such that I can pass in a url, and receive data via GET. Sooo… we ultimately would like something like this:
data = GET.request(“someurl.com”);
To try and accomplish this, I use the WWW object. Now, in order to give the WWW object time to download, we need to have this happening inside a MonoBehaviour Object and yield the results. So I got this, which works:
public class main : MonoBehavior
{
IEnumerator Start()
{
WWW www = new WWW("http://www.someurl.com/blah.php?action=awesome_stuff");
yield return www;
Debug.Log(www.text);
}
}
What I really want is this:
public class main : MonoBehavior
{
IEnumerator Start()
{
GET request = new GET("http://www.someurl.com/blah.php?action=awesome_stuff");
Debug.Log(request.get_data()); // Where get_data() returns the data (which will be text) from the request.
}
}
Now I have the main script attached to the single GameObject in the Hierarchy (called root)
Do I need to have the GET script attached to the root GameObject as well? Can I do that dynamically from main?
Ultimately, I need a solution that allows me to easily send GET and POST requests.
Cheers!