Snaparazzi/Assets/Scripts/CameraManager.cs

31 lines
867 B
C#
Raw Normal View History

2024-01-27 10:26:34 +00:00
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class CameraManager : MonoBehaviour
{
// Start is called before the first frame update
IEnumerable Start()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
Debug.Log("webcam found");
}
else
{
Debug.Log("webcam not found");
}
}
// Update is called once per frame
void Update()
{
WebCamDevice[] devices = WebCamTexture.devices;
var webcamTexture = new WebCamTexture(devices[0].name);
gameObject.GetComponent<RawImage>().texture = webcamTexture;
gameObject.GetComponent<RawImage>().material.mainTexture = webcamTexture;
webcamTexture.Play();
}
}