Skip to content

Instantly share code, notes, and snippets.

@ikriz

ikriz/Webcam.cs

Last active Jan 24, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@AdrianArielRodriguez AdrianArielRodriguez commented Jan 24, 2019

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