Last active
January 24, 2019 15:48
-
-
Save ikriz/9144031 to your computer and use it in GitHub Desktop.
Webcam Script to display Webcam Textures [http://www.ikriz.nl/2011/12/23/unity-video-remake/]
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; | |
public class Webcam : MonoBehaviour | |
{ | |
public MeshRenderer[] UseWebcamTexture; | |
private WebCamTexture webcamTexture; | |
void Start() | |
{ | |
webcamTexture = new WebCamTexture(); | |
foreach(MeshRenderer r in UseWebcamTexture) | |
{ | |
r.material.mainTexture = webcamTexture; | |
} | |
renderer.material.mainTexture = webcamTexture; | |
webcamTexture.Play(); | |
} | |
void OnGUI() | |
{ | |
if (webcamTexture.isPlaying) | |
{ | |
if (GUILayout.Button("Pause")) | |
{ | |
webcamTexture.Pause(); | |
} | |
if (GUILayout.Button("Stop")) | |
{ | |
webcamTexture.Stop(); | |
} | |
} | |
else | |
{ | |
if (GUILayout.Button("Play")) | |
{ | |
webcamTexture.Play(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello very good job!
I wanted to ask you for part of the code:
in unity3d.2017 it tells me that it is obsolete, do you know how to modify it?
Thank you