[Feng yuchong] unity3d Tutorial: Web server: (2) download images from servers

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.