1.
创建一个Quad
2.
创建一个材质 Materia 把shader属性设置unlit/Texture (为等下摄像机显示在quad做准备
)
3.
创建摄像机对象,并开启。
using UnityEngine;
using System.Collections;
public class CameraTest : MonoBehaviour {
WebCamTexture tex;
IEnumerator Start () {
yield return new WaitForSeconds(3);//等待三秒
WebCamDevice[] devices = WebCamTexture.devices; //查找可用的摄像机
var tex = new WebCamTexture(devices[0].name,1200,900); //使用第一个摄像机
GetComponent<MeshRenderer>().material.mainTexture = tex; //把摄像机拍照的
using System.Collections;
public class CameraTest : MonoBehaviour {
WebCamTexture tex;
IEnumerator Start () {
yield return new WaitForSeconds(3);//等待三秒
WebCamDevice[] devices = WebCamTexture.devices; //查找可用的摄像机
var tex = new WebCamTexture(devices[0].name,1200,900); //使用第一个摄像机
GetComponent<MeshRenderer>().material.mainTexture = tex; //把摄像机拍照的
//图片显示在Quad
tex.Play();
}
// Update is called once per frame
void Update () {
}
}
}
// Update is called once per frame
void Update () {
}
}
5. 材质与脚本一起添加到Quad :注意摄像正对Quad .