Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created March 26, 2014 07:47
Show Gist options
  • Select an option

  • Save yoggy/9778459 to your computer and use it in GitHub Desktop.

Select an option

Save yoggy/9778459 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class httptexture : MonoBehaviour {
private Texture2D tex2d;
private delegate void WWWAction (WWW www);
void Start () {
tex2d = new Texture2D (512, 512, TextureFormat.ARGB32, false, false);
renderer.material.mainTexture = tex2d;
}
void Update () {
}
void OnGUI () {
StartCoroutine (Download ((www) => {
www.LoadImageIntoTexture (tex2d);
}));
}
IEnumerator Download (WWWAction action)
{
string url = "http://localhost:10080/camera.jpg?t=" + Time.time;
using (WWW www = new WWW (url)) {
while (!www.isDone && string.IsNullOrEmpty( www.error )) {
yield return null;
}
action (www);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment