Unity3D中新建一個工程,加一個Plane,新建一個C# 腳本,將這個腳本添加到Plane上,調用攝像頭。(如果顯示的圖片居然是翻轉的,Plane的Rotation 值就可以了)
以下是腳本內容:
using UnityEngine; using System.Collections; public class C : MonoBehaviour { WebCamTexture webcamTexture; // Use this for initialization void Start () { WebCamDevice[] devices = WebCamTexture.devices; if (devices.Length > 0) { webcamTexture = new WebCamTexture(devices[0].name, 320, 240, 25);
//renderer.material.mainTexture = webcamTexture;
//這里和之前版本不一樣了
GetComponent<Render>().material.mainTexture = webcamTexture;
webcamTexture.Play(); } } // Update is called once per frame void Update () { } }
