Skip to content

Instantly share code, notes, and snippets.

@masayuki5160
Created January 24, 2014 06:30
Show Gist options
  • Save masayuki5160/8592951 to your computer and use it in GitHub Desktop.
Save masayuki5160/8592951 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class testHttp : MonoBehaviour {
private string res;
IEnumerator download () {
string url = "http://www.unity3d.com/";
WWW www = new WWW(url);
yield return www;
res = "";
if (!string.IsNullOrEmpty(www.error) || string.IsNullOrEmpty(www.text)) {
// Http通信失敗
res = "error";
} else {
// コンテンツ取得したので中身を格納
res = www.text;
}
}
void OnGUI () {
if (GUI.Button(new Rect(5, 5, 200, 20), "Test")) {
// ボタンが押されたらHttp通信開始
StartCoroutine(download());
}
GUI.Label(new Rect(5, 30, Screen.width, 200), res);
}
}
@masayuki5160
Copy link
Author

【参考】http://d.hatena.ne.jp/nakamura001/20120825/1345858810

てかまんまやんw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment