본문 바로가기
프로그래밍/Unity

Texture 다운로드

by neive 2020. 8. 25.
728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

public class Main : MonoBehaviour
{
    public string m_URL;
    public RawImage m_RawImage;

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Download_Image(m_URL));
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    IEnumerator Download_Image(string URL)
    {
        UnityWebRequest www = UnityWebRequestTexture.GetTexture(URL);
        var async = www.SendWebRequest();
        while (!async.isDone)
            yield return null;

        if (www.isNetworkError || www.isHttpError)
            Debug.Log(www.error);
        else
            m_RawImage.texture = DownloadHandlerTexture.GetContent(www);
    }
}
728x90

댓글