并不全面,需要后期更新,但东西都对
运行后
using UnityEngine;
using System.Collections;
/// <summary>
/// www是一个简单的访问网页的类
///是一个能够检索统一资源定位符的小工具
///通过连接www(URL)在后台开始进行下载
///并通过yield return返回下载后的www对象
/// </summary>
public class WWWScript : MonoBehaviour {
public string URL = string.Empty;
// Use this for initialization
IEnumerator Start () {
//可以给URL一个网网址也可以给一个本地的路径
URL = "file:///Users/student/Desktop/a.jpg";//本地的路径
WWW www = new WWW (URL);//定义一个www类型的对象
yield return www;//返回下载的值
if (www.error != null) {//判断下载的资源是否有错误
Debug.Log("Error: "+ www.error);
yield break;
}
//替换材质
this.gameObject.GetComponent<Renderer> ().material.mainTexture = www.texture;
}
// Update is called once per frame
void Update () {
}
}
本文介绍了一个Unity中的简单网页访问类WWWScript,该类可用于检索URL并下载资源到本地。通过实例演示了如何使用该组件从指定路径加载图片,并将其设置为游戏对象的纹理。
8万+

被折叠的 条评论
为什么被折叠?



