OriginalArticleIf you need to reprint, please note: Reprinted from Fengyu Chong unity3d tutorial Institute
Download images from Web Servers
In the previous lecture, Feng yuchong introduced the Wamp Server and its installation. This section describes how to download content from the server to unity3d.Program.
Drag a picture under the WWW folder under wamp;here, use cat.jpg, enter http: // localhost/cat.jpg, you can see the following picture,
Create a unity Project Creates a sphere, creates a material with any name, and assigns the material to the sphere. Create a script named getimage, Code As follows, Using unityengine; Using system. collections;
Public class getimage: monobehaviour { Void ongui () { If (GUI. Button (New rect (,), "Get image ")) { Startcoroutine (getwebimage ()); } } Ienumerator getwebimage () { WWW mywww = new WWW ("http: // localhost/cat.jpg "); Yield returnMywww; Renderer. Material. maintexture = mywww. texture; } }
After running, click the button in the upper left corner and the white ball will be assigned images on the webpage as textures. How is it easy?
Summary : The core of unity3d reading HTTP content is mywww. = WWW (URL), based on what type of content you read For mywww. Text reading, mywww. texture is used for reading images, and mywww. Movie is used for reading videos. It can be used or stored later.