Created
February 9, 2015 03:18
-
-
Save neuman/5ac76d16aff06ab5de50 to your computer and use it in GitHub Desktop.
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 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