コルーチン関連

処理内容

  1. ボタンを表示
  2. ボタンを押すと指定したSceneに遷移
  3. 裏で、指定したURLに接続

ソースコード

using UnityEngine;
using System.Collections;

public class Title : MonoBehaviour {
	void OnGUI () {
		if (GUI.Button(new Rect(Screen.width/2 -100 , 100, 200, 50), "GAME START"))
		{
			Application.LoadLevel("particles");
			StartCoroutine("LoadData");

		}
	}

	private IEnumerator LoadData() {
		string url = "http://localhost:3000";
		WWW hoge = new WWW(url);
		while (!hoge.isDone) {
			yield return null;
		}
	}
}

少しハマったところ

↑上記ソースコードの、

WWW hoge = new WWW(url);

の部分で当初、変数hogeの前の型宣言を書かずにビルドしたら、

hoge does not exist in the current context

と怒られた。