Unity 网络请求(1)
using UnityEngine; using System.Collections; public class Scene1 : MonoBehaviour { //下载图片的容器 private Texture texture1; IEnumerator loadNetWork() { if(texture1 == null) { //网络请求路径 WWW data = new WWW("http://ww1.sinaimg.cn/bmiddle/61e61e8cjw1e6m3iaag6nj20fk0bc0ul.jpg"); //等待下载完成 yield return data; //得到下载的图片 texture1 = data.texture; } //将下载的图片显示的物体上 renderer.material.mainTexture = texture1; } void OnGUI() { //点击Button开始下载 if(GUILayout.Button("NETDowload")) { StartCoroutine(loadNetWork()); } } // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }