|
| 1 | +using System.Collections; |
| 2 | +using System.Collections.Generic; |
| 3 | +using UnityEngine; |
| 4 | + |
| 5 | +// usage: attach this script to any gameobject in which you want to render the webcam display |
| 6 | +// create a material, use Unlit/Texture as a shader and place it to the gameobject's material placeholder in the mesh renderer component |
| 7 | + |
| 8 | +namespace UnityLibrary |
| 9 | +{ |
| 10 | + public class WebCamDisplay : MonoBehaviour |
| 11 | + { |
| 12 | + void Start() |
| 13 | + { |
| 14 | + WebCamTexture webCam = new WebCamTexture(); |
| 15 | + webCam.deviceName = WebCamTexture.devices[0].name; |
| 16 | + this.GetComponent<MeshRenderer>().material.mainTexture = webCam; |
| 17 | + webCam.Play(); |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
0 commit comments