using UnityEngine; using System.Collections; public class WebcamController : MonoBehaviour { public Renderer renderer; void Start() { WebCamTexture webcamTexture = new WebCamTexture(); renderer = GetComponent(); renderer.material.mainTexture = webcamTexture; webcamTexture.Play(); } }
using UnityEngine; using System.Collections; public class WebcamController : MonoBehaviour { public Renderer renderer; public string deviceName; void Start() { WebCamDevice[] devices = WebCamTexture.devices; WebCamTexture webcamTexture; if (devices.Length > 0) { if (deviceName != null) webcamTexture = new WebCamTexture(deviceName); else webcamTexture = new WebCamTexture(); renderer = GetComponentIn this example, we first check for available cameras. We then assign a specific camera by specifying its name in deviceName. If no name is given, it defaults to the first camera. We then proceed to assign it to the renderer's texture and play the webcam. **Package Library** WebCamTexture is part of the UnityEngine library, which is included in Unity. No additional package or library is required.(); renderer.material.mainTexture = webcamTexture; webcamTexture.Play(); } } }