nirasan's tech blog

趣味や仕事の覚え書きです。Linux, Perl, PHP, Ruby, Javascript, Android, Cocos2d-x, Unity などに興味があります。

NGUI でインターネット上の画像を表示するには

  • WWW で画像を読み込み、UITexture で表示する。

サンプル

  • 以下のスクリプトを任意のオブジェクトにアタッチして実行する。
using UnityEngine;
using System.Collections;

[RequireComponent(typeof (UITexture))]
public class LoadTextureFromWWWSample : MonoBehaviour {

	public string url;

	void Start () {
		UITexture texture = GetComponent<UITexture> ();
		StartCoroutine (SetImage (texture, url));
	}
	
	IEnumerator SetImage (UITexture t, string url) {
		WWW www = new WWW(url);
		yield return www;
		t.mainTexture = www.texture;
	}
}