Skip to content

Instantly share code, notes, and snippets.

@oismaelash
Last active March 9, 2019 16:44
Show Gist options
  • Save oismaelash/54ab35108f9213bd1da3f9e48ab94840 to your computer and use it in GitHub Desktop.
Save oismaelash/54ab35108f9213bd1da3f9e48ab94840 to your computer and use it in GitHub Desktop.
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class StoreCard : MonoBehaviour
{
[SerializeField] private Image imgStore;
private void OnEnable()
{
StartCoroutine(LoadImageStore_Coroutine("https://unity3d.com/profiles/unity3d/themes/unity/images/ui/ui/unity-logo-black.svg"));
}
private IEnumerator LoadImageStore_Coroutine(string url)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(Curl))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError)
{
Debug.Log("Error load store logo: " + webRequest.error);
}
else
{
Texture2D texture = new Texture2D(100, 100);
texture.LoadImage(webRequest.downloadHandler.data);
texture.Apply();
imgStore.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment