如何通过WWW下载图片 学习笔记

本文介绍了在Unity3D中利用WWW类下载网络图片,并将其应用于物体材质的方法。WWW不仅可以下载图片,还能处理文本、音频等数据。通过监控isDone属性检查下载状态,使用texture属性获取Texture2D对象,实现对下载图片的进一步操作。同时,还提到了构造器、各种返回值以及如LoadImageIntoTexture()等函数的应用。
摘要由CSDN通过智能技术生成
方法
using UnityEngine;

public class Api : MonoBehaviour
{

public string  url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";

    IEnumerator Start()
    {

        WWW www = new WWW(url);

        yield return www;

        Renderer renderer = GetComponent<Renderer>();
        renderer.material.mainTexture = www.texture;
    }
	
}

这种方法是在网络中下载图片,并赋予给物体材质,物体需要一个mesh rendeer

www不仅可以下载图片,还可以下载例如文本,音频

Variables变量
text
Returns the contents of the fetched web page as a string (Read Only).
通过网页获取并以字符串的形式返回内容(只读)。
bytes
Returns the contents of the fetched web page as a byte array (Read Only).
以字节组的形式返回获取到的网络页面中的内容(只读)。
error
Returns an error message if there was an error during the download (Read Only).
返回一个错误消息,在下载期间如果产生了一个错误的话。(只读)
texture
Returns a Texture2D generated from the d

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值