Skip to content

Instantly share code, notes, and snippets.

@neuman
Created February 9, 2015 03:18
Show Gist options
  • Save neuman/5ac76d16aff06ab5de50 to your computer and use it in GitHub Desktop.
Save neuman/5ac76d16aff06ab5de50 to your computer and use it in GitHub Desktop.
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections;
using System.Collections.Generic;
using System;
public class WebImageDisplay : MonoBehaviour
{
public List<string> urls = new List<string>();
public float duration = 3f;
void Start()
{
renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
StartCoroutine (slideshow ());
}
IEnumerator UpdateImage(string url)
{
Debug.Log("reloading webcam");
WWW www = new WWW(url);
yield return www;
www.LoadImageIntoTexture((Texture2D)renderer.material.mainTexture);
}
IEnumerator slideshow() // Not void
{
int cursor = 0;
while (true) {
StartCoroutine (UpdateImage (urls.ToArray () [cursor]));
yield return new WaitForSeconds (3);
cursor = (cursor + 1) % urls.ToArray ().Length;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment