unity3d調(diào)用手機或電腦攝像頭
更新時間:2015年03月30日 12:04:55 投稿:hebedich
這個是在網(wǎng)上看到的,經(jīng)測試可以在電腦上運行,確實調(diào)用了本地攝像頭。有需要的小伙伴可以參考下。
功能很實用,代碼很簡單,這里就不多廢話了。
WebCamTexture:網(wǎng)絡(luò)攝像頭材質(zhì)
WebCamTexture.Play() 播放;
WebCamTexture.Pause() 暫停;
WebCamTexture.Stop() 停止;
//經(jīng)測試此代碼可以使用,當(dāng)你綁定到游戲物體時盡可以了、
using unityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public string deviceName;//這個雖然public,但無需為其綁定變量,直接運行,默認(rèn)調(diào)用,顯示本地攝像機的名稱
WebCamTexture webCam;
// Use this for initialization
void Start () {
WebCamDevice[] devices = WebCamTexture.devices;
deviceName = devices[0].name;
webCam = new WebCamTexture(deviceName, 400, 300, 12);
renderer.material.mainTexture = webCam;
webCam.Play();
}
// Update is called once per frame
void Update () {
}
}
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
C#查找對象在ArrayList中出現(xiàn)位置的方法
這篇文章主要介紹了C#查找對象在ArrayList中出現(xiàn)位置的方法,涉及C#中IndexOf方法的使用技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04
C#中使用XmlDocument類來創(chuàng)建和修改XML格式的數(shù)據(jù)文件
這篇文章主要介紹了C#中使用XmlDocument類來創(chuàng)建和修改XML格式的數(shù)據(jù)文件的方法,XmlDocument類被包含在.NET框架中,需要的朋友可以參考下2016-04-04

