C# solution
using UnityEngine;
using System.Collections;
public class WebCam: MonoBehaviour {
void Start() {
WebCamDevice[] devices = WebCamTexture.devices;
if (devices.Length > 0) {
WebCamTexture webcamTexture = new WebCamTexture(devices[0].name, 320, 240, 10);
renderer.material.mainTexture = webcamTexture;
webcamTexture.Play();
}
}
}
JavaScript solution
function Start() {
var devices: WebCamDevice[] = WebCamTexture.devices;
if (devices.length > 0) {
var webcamTexture: WebCamTexture = WebCamTexture(320, 240, 10);
renderer.material.mainTexture = webcamTexture;
webcamTexture.Play();
}
}