Skip to content

Instantly share code, notes, and snippets.

@ikriz
Last active January 24, 2019 15:48
Show Gist options
  • Save ikriz/9144031 to your computer and use it in GitHub Desktop.
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/]
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();
}
}
}
}
@AdrianArielRodriguez
Copy link

hello very good job!
I wanted to ask you for part of the code:

renderer.material.mainTexture = webcamTexture; //line 16

in unity3d.2017 it tells me that it is obsolete, do you know how to modify it?
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment