Unity3D调用摄像头显示当前拍摄画面


  • using UnityEngine;  
  • using System.Collections;  
  •   
  • public class CameraTest : MonoBehaviour  
  • {  
  •     public WebCamTexture cameraTexture;  
  •     public string cameraName="";  
  •     private bool isPlay = false;  
  •     // Use this for initialization  
  •     void Start()  
  •     {  
  •         StartCoroutine(Test());  
  •     }  
  •   
  •     // Update is called once per frame  
  •     void Update()  
  •     {  
  •   
  •     }  
  •   
  •     IEnumerator Test()  
  •     {  
  •         yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);  
  •         if (Application.HasUserAuthorization(UserAuthorization.WebCam))  
  •         {  
  •             WebCamDevice[] devices = WebCamTexture.devices;  
  •             cameraName = devices[0].name;  
  •             cameraTexture = new WebCamTexture(cameraName, 400, 300, 15);  
  •             cameraTexture.Play();  
  •             isPlay = true;  
  •         }  
  •     }  
  •   
  •     void OnGUI()  
  •     {  
  •         if (isPlay)  
  •         {  
  •             GUI.DrawTexture(new Rect(0, 0, 400, 300), cameraTexture, ScaleMode.ScaleToFit);  
  •         }  
  •     }  


  • 免责声明!

    本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



     
    粤ICP备18138465号  © 2018-2025 CODEPRJ.COM