Unity WebPlayerとブラウザ内UIの連携

f:id:peroon:20130203174302p:plain
WebPlayer外のボタンUIを押して、Unity内に爆発インスタンスを作成できる。
逆に、Unity内からHTML内のJSを呼ぶこともできる。
https://github.com/peroon/unity_webplayer_browser_connection

//Unity内のJSはこんな感じ

var detonator_prefab:GameObject;

function OnGUI () {

        //call function a() in HTML
	if (GUI.Button (Rect (10,10,150,100), "JS a()")) {
		Application.ExternalCall( "a", "parameter string for a()" );
	}

        //call function b() in HTML
	if (GUI.Button (Rect (10,10+110,150,100), "JS b()")) {
		Application.ExternalCall( "b", "parameter string for b()" );
	}

        //explosion
	if (GUI.Button (Rect (10,10+220,150,100), "detonator()")) {
		detonator();
	}
}

function detonator(){
	Instantiate(detonator_prefab, Vector3(0,0,0), Quaternion.identity);
}