- 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);
- }
- }
- }
Unity3D调用摄像头显示当前拍摄画面
最新推荐文章于 2025-01-11 18:24:26 发布
本文介绍如何在Unity中实现摄像头的获取与显示功能,通过请求用户授权并选择摄像头设备,进而展示摄像头实时画面。
2015

被折叠的 条评论
为什么被折叠?



