unity经常会从服务器上面获取URL来显示图片,下面是具体的代码实现:
IEnumerator GetImage(string url)
{
WWW www = new WWW(url);
yield return www;
if (string.IsNullOrEmpty(www.error))
{
Texture2D tex = www.texture;
Sprite temp = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0));
this.img_erweima.sprite = temp; //设置的图片,显示从URL图片
}
}