Skip to content

Instantly share code, notes, and snippets.

@RomainKurtz
Created February 7, 2017 12:03
Show Gist options
  • Save RomainKurtz/dcf70dacf1a6c92bc63abef0105a4017 to your computer and use it in GitHub Desktop.
Save RomainKurtz/dcf70dacf1a6c92bc63abef0105a4017 to your computer and use it in GitHub Desktop.
public void StartLoadingPhoto(){
IEnumerator coroutine = LoadPhoto("http://website/photo.png");
StartCoroutine(coroutine);
}
IEnumerator LoadPhoto(string url)
{
string url = url;
Texture2D tex;
tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
WWW www = new WWW(url);
yield return www;
www.LoadImageIntoTexture(tex);
Sprite sprite = Sprite.Create(tex, new Rect(0,0,300,300), new Vector2(0.5f, 0.5f), 100);
Photo.sprite = sprite;
//GetComponent<Renderer>().material.mainTexture = tex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment