美文网首页
使用www下载图片,并贴到cube上

使用www下载图片,并贴到cube上

作者: 浪荡少年 | 来源:发表于2019-07-13 16:45 被阅读0次

ausing System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System.IO;

using UnityEngine.UI;

public class HttpText : MonoBehaviour {

    //Image image;

    MeshRenderer mesh;

    IEnumerator Start()

    {

        mesh = this.GetComponent<MeshRenderer>();

        //image = this.GetComponent<Image>();

        string picture = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1548085394986&di=2c9c0f3e0662ceca690480b614592d1d&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2Fdc2bffb262eab801646348ebacaa899f7786670f3c1fb-ZSyM5d_fw658";

        WWW www = new WWW(picture);

        yield return www;

        //给Image添加图片

        //Sprite sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0.5f, 0.5f));

        //image.sprite = sprite;

        //下载图片  没成功  不怪我

        //string path = @"C:\Users\Administrator\Desktop\图片.jpg";

        //FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write);

        //stream.Write(www.bytes, 0, picture.Length);

        //stream.Close();

        //Debug.Log("完成");

        //完成在Cube的添加图片

        //GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

        //Sprite sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0.5f, 0.5f));

        mesh.material.mainTexture = www.texture;

    }

// Update is called once per frame

void Update () {

}

}

相关文章

网友评论

      本文标题:使用www下载图片,并贴到cube上

      本文链接:https://www.haomeiwen.com/subject/iwjmkctx.html