using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TestRGB : MonoBehaviour { public int index; int w = 1280; int h = 720; WebCamTexture RGBCamTexture; // Start is called before the first frame update void Start() { WebCamDevice[] devices = WebCamTexture.devices; if (devices.Length == 0) { Debug.Log("No webcam devices found."); return; } // 使用第一个可用的摄像头设备(你可以根据需要选择其他设备) RGBCamTexture = new WebCamTexture(devices[index].name, w, h, 30); Debug.Log("开启摄像头" + devices[index].name); // 开始摄像头捕捉 RGBCamTexture.Play(); if (this.GetComponent() != null) { this.GetComponent().texture = RGBCamTexture; this.GetComponent().transform.localEulerAngles = new Vector3(0, 0, 0); } } }