Skip to content

Instantly share code, notes, and snippets.

@maxoja
Created July 15, 2018 08:09
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save maxoja/957c757a83a0328833e4b9f031db7222 to your computer and use it in GitHub Desktop.
Save maxoja/957c757a83a0328833e4b9f031db7222 to your computer and use it in GitHub Desktop.
Unity How to : Load Image from WebLink or URL
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ImageLoader : MonoBehaviour
{
public string url = "https://i.pinimg.com/originals/9e/1d/d6/9e1dd6458c89b03c506b384f537423d9.jpg";
public Renderer thisRenderer;
// automatically called when game started
void Start()
{
StartCoroutine(LoadFromLikeCoroutine()); // execute the section independently
// the following will be called even before the load finished
thisRenderer.material.color = Color.red;
}
// this section will be run independently
private IEnumerator LoadFromLikeCoroutine()
{
Debug.Log("Loading ....");
WWW wwwLoader = new WWW(url); // create WWW object pointing to the url
yield return wwwLoader; // start loading whatever in that url ( delay happens here )
Debug.Log("Loaded");
thisRenderer.material.color = Color.white; // set white
thisRenderer.material.mainTexture = wwwLoader.texture; // set loaded image
}
}
@Alperek
Copy link

Alperek commented Aug 17, 2020

Thanks.

@alex2060
Copy link

thank you

@olgv
Copy link

olgv commented Nov 27, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment