闲话少说,上代码,google上搜来的代码,不过里面有bug,不能顺利切换,下面的代码是已经修改过的,经测试,可以正常运行。
<pre class="css" name="code">using System;
using UnityEngine;
using System.IO;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
//public GUITexture mytext;
public UITexture mytext;
private WebCamTexture frontWebcamTexture = null;
private WebCamTexture rearWebcamTexture = null;
private WebCamDevice[] devices;
[HideInInspector]
public WebCamTexture activeCam;
bool flag = false ;
static int cameraIndex = 0 ;
/* 按钮控件 */
public GameObject btn_shot ;
public GameObject btn_change_camera ;
void Awake () {
for( int i = 0 ; i < WebCamTexture.devices.Length ; i++ )
NGUIDebug.Log(WebCamTexture.devices[i].name);
devices = WebCamTexture.devices;
string frontCamName = "";
string rearCamName = "";
unity3d 中控制手机前后摄像头切换
最新推荐文章于 2023-04-18 20:45:41 发布
这篇博客主要展示了如何在Unity3D中通过代码实现手机前后摄像头的切换。通过获取设备的摄像头列表,判断并设置前后摄像头,然后在点击事件中切换摄像头,并进行拍照保存。提供了完整的代码示例。
摘要由CSDN通过智能技术生成