public GameObject gameObj;
Texture2D texture2DLocal;
Texture2D texture2DWeb;
string localTexturePath;
string webTexturePath;
void OnGUI()
{
if(GUILayout.Button("下载本机贴图"))
{
StartCoroutine(loadLocal());
}
if(GUILayout.Button("下载网络贴图"))
{
StartCoroutine(loadWeb());
}
}
// Use this forinitialization
void Start() {
localTexturePath = "file://"+ Application.dataPath + "//33.jpg";
webTexturePath = "http://www.cnsphoto.com/CNSPhotoUse/PicLib/MidPic/12p/PhotoN/121026/121026074ta_2.jpg";
}
// Update iscalled once per frame
void Update()
{
}
IEnumerator loadLocal()
{
WWW wwwDate = new WWW(localTexturePath);
yield return wwwDate;
texture2DLocal = wwwDate.texture;//得到下载的贴图
gameObj.renderer.material.mainTexture =texture2DLocal;
}
IEnumerator loadWeb()
{
WWW wwwData = new WWW(webTexturePath);
yield return wwwData;
texture2DWeb = wwwData.texture;
gameObj.renderer.material.mainTexture =texture2DWeb;
}