Unity 3d UI获取外部摄像头拍摄
3D环境下调用外部摄像头的方法网络上有很多,在此不过多说,本方法是在2D环境下利用UI来调用外部摄像头进行拍摄,总体而言,两种环境下所用到的核心方法是一样的。
1、创建一个RawImagin,并命名为CameraPlay

2、创建一个脚本,命名为PlaneManager,将脚本随便挂在一个物体上。脚本中的public RawImage rawImage;要记得在Inspector面板中把CameraPlay添上去
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlaneManager : MonoBehaviour
{
public string DeviceName;
//public Vector2 CameraSize;
public float CameraFPS;
//接收返回的图片数据
WebCamTexture _webCamera;
//public GameObject Plane;//作为显示摄像头的面板
public RawImage rawImage;
void OnGUI()
{
if (GUI.Button(new

本文介绍如何在Unity3D的2D环境中使用UI组件调用外部摄像头进行实时拍摄。通过创建RawImage和自定义脚本来实现摄像头的开启、关闭及预览功能。
最低0.47元/天 解锁文章
1273





