Created
July 15, 2018 08:09
-
-
Save maxoja/957c757a83a0328833e4b9f031db7222 to your computer and use it in GitHub Desktop.
Unity How to : Load Image from WebLink or URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
thank you
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.