赞
踩
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class TestImage : MonoBehaviour { [SerializeField] private Image image; public void LoadImage(string url) { StartCoroutine(LoadTexture(url)); } IEnumerator LoadTexture(string url) { UnityWebRequest uwr = UnityWebRequest.Get(url); DownloadHandlerTexture tex = new DownloadHandlerTexture(true); uwr.downloadHandler = tex; yield return uwr.SendWebRequest(); if (uwr.result == UnityWebRequest.Result.ConnectionError) { Debug.LogError(uwr.error); } else { Texture2D t2d = new Texture2D(1, 1); t2d = tex.texture; Sprite spr = Sprite.Create(t2d, new Rect(0, 0, t2d.width, t2d.height), new Vector2(0.5f, 0.5f)); image.sprite = spr; } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。