Skip to content

Instantly share code, notes, and snippets.

@snaka
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save snaka/11278774 to your computer and use it in GitHub Desktop.

Select an option

Save snaka/11278774 to your computer and use it in GitHub Desktop.
HTTPでWebサーバからレスポンスを受け取る ref: http://qiita.com/snaka/items/4e384a7f9ce80b98b71b
using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {
public string url = "http://www.google.com";
public string output = "(ここに結果を表示)";
private GetViaHttp http;
void Start() {
http = GetComponent<GetViaHttp>();
}
void OnGUI() {
// Button
if(GUI.Button(new Rect(30, 30, 100, 30), "GET via HTTP")) {
Debug.Log("GET!!!");
StartCoroutine("GetUrl");
}
// TextArea for Output
GUI.TextArea(new Rect(30, 70, 800, 600), output);
}
private IEnumerator GetUrl() {
Debug.Log("Start2");
WWW www = new WWW(url);
yield return www;
Debug.Log(www.text);
output = www.text;
}
}
using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {
public string url = "http://www.google.com";
public string output = "(ここに結果を表示)";
private GetViaHttp http;
void Start() {
http = GetComponent<GetViaHttp>();
}
void OnGUI() {
// Button
if(GUI.Button(new Rect(30, 30, 100, 30), "GET via HTTP")) {
Debug.Log("GET!!!");
StartCoroutine("GetUrl");
}
// TextArea for Output
GUI.TextArea(new Rect(30, 70, 800, 600), output);
}
private IEnumerator GetUrl() {
Debug.Log("Start2");
WWW www = new WWW(url);
yield return www;
Debug.Log(www.text);
output = www.text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment