Created
March 26, 2014 07:47
-
-
Save yoggy/9778459 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
| 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