unity3d 实现连接外置摄像头实例

新建场景,新建一个cube或者plane之类的有renderer的物体,然后新建C#脚本Test,拖上去,运行即可

using UnityEngine;
using System.Collections;
public class Test : 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 {
}
}
// Update is called once per frame
void Update () {
}
}

 

未经允许不得转载:第一Unity3D » unity3d 实现连接外置摄像头实例

赞 (0)