Display live camera feed in Unity
In case it helps, I'm posting an answer, based on the accepted answer above, written as a C# script (the accepted answer was in JavaScript). Just attach this script to a GameObject that has a renderer attached, and it should work.
public class DisplayWebCam : MonoBehaviour
{
void Start ()
{
WebCamDevice[] devices = WebCamTexture.devices;
// for debugging purposes, prints available devices to the console
for(int i = 0; i < devices.Length; i++)
{
print("Webcam available: " + devices[i].name);
}
Renderer rend = this.GetComponentInChildren<Renderer>();
// assuming the first available WebCam is desired
WebCamTexture tex = new WebCamTexture(devices[0].name);
rend.material.mainTexture = tex;
tex.Play();
}
}
Yes that certainly is possible and luckily for you Unity3D actually supports it quite well out of the box. You can use a WebCamTexture to find the webcam and render it to a texture. From there you can choose to render the texture on anything in the 3D scene, including your virtual television screen of course.
It looks pretty self explanatory but the below code should start you off.
List and print out the connected devices it detects:
var devices : WebCamDevice[] = WebCamTexture.devices;
for( var i = 0 ; i < devices.length ; i++ )
Debug.Log(devices[i].name);
Connect to an attached webcam and send the image data to a texture:
WebCamTexture webcam = WebCamTexture("NameOfDevice");
renderer.material.mainTexture = webcam;
webcam.Play();