Unity3d Download and save the pictures: Unity3d 2013-06-24 15:03 3609 people read reviews (2) Favorite report Unity3d picture URL code is as follows: [CSharp] View plaincopy using Unityengine ; Using System.Collections; Using System.IO; public class Downpicture:monobehaviour {public gameobject plane; www www; String FilePath; Texture2d test; Texture2d newtexture; Use the this for initialization void Start () {FilePath = Application.datapath + "/resources/pictu Re.jpg "; if (System.IO.File.Exists (FilePath)) {Debug.Log ("File already exists"); Test = (texture2d) resources.load ("Picture", typeof (Texture2d)); plane.renderer.material.mainTexture = test; } else {Debug.Log ("file start download"); Startcoroutine (GetImage ()); }}//update is called once per frame void update () {} ienum Erator GetImage () {string URL = "Http://192.168.2.105:8080/Test/picture/1.jpg"; www = new www (URL); yield return www; Newtexture = www.texture; byte[] Pngdata = Newtexture.encodetopng (); File.writeallbytes (FilePath, pngdata); } void Ongui () {if (Www.isDone) {Plane.renderer.material.mai Ntexture = newtexture; } } }
Download and save the Unity3d pictures