1130526 載入相機
by 黃國哲 2024-05-26 19:01:51, Reply(0), Views(129)
開啟一個新專案,直接複製Documment的語法,然後加上黃色的部分
宣告一個你要用來顯示照相機的畫面UI物件,然後在最後的地方將那個物件紋理切換成你的webcamTexture。
這裡只能用RawImage~
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class cameracontrol : MonoBehaviour
{
public WebCamTexture webcamTexture ;
public RawImage raw;
// Start is called before the first frame update
void Start()
{
WebCamDevice[] devices = WebCamTexture.devices;
WebCamTexture webcamTexture = new WebCamTexture();
if (devices.Length > 0)
{
webcamTexture.deviceName = devices[0].name;
webcamTexture.Play();
raw.texture = webcamTexture;
}
}
// Update is called once per frame
void Update()
{
}
}
Reply