轉載於Unity3d聖典裏面,具體哪位大俠寫的我忘咯。html
- using UnityEngine;
- using System.Collections;
-
- public class CameraTest : MonoBehaviour {
-
- public string deviceName;
- WebCamTexture tex;
- // Use this for initialization
- IEnumerator Start()
- {
- //獲取受權
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- deviceName = devices[0].name;
- tex = new WebCamTexture(deviceName, 400, 300, 12);
- renderer.material.mainTexture = tex;
- tex.Play();
- }
- else
- {
- }
- }
- }
綁定在一個帶有Render組件的物體上就好了。web