Hello everybody! Im trying to build up a simple WebGL app with Unity and get the access to devices camera in browser. I found out some solutions, but it doesnt work for me, can anybody help to solve it please? I was also googling this problem, but there was no any solutions... I Tried these two methods below, it works good if I build an apk or windows build but for WebGL it doesnt. When I build it and run it shows 0 devices, has an access rights , but 0 devices. Tried WebGL build on android, ios, macOs, but it always shows 0 devices and I never get a UserAuthorization request to provide an access to my device
s cameras. My full script is below. I tried it on Unity version: 2022.2.0b4, 2022.1.1f1, 2021.3.6f1. Browsers: Google, Safari
StartCamera, StopCamera, SwapCamera methods are linked to Buttons in inspector
PLEASE ANYBODY HELP
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace MultiWebcam
{
public sealed class CameraController : MonoBehaviour
{
[SerializeField] private RawImage _display;
private WebCamDevice[] devices;
private WebCamTexture _texture;
private int _currentCameraIndex = 0;
private void Awake()
{
StartCoroutine(Start());
}
private IEnumerator Start()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
Debug.Log("webcam found");
devices = WebCamTexture.devices;
for (int cameraIndex = 0; cameraIndex < devices.Length; ++cameraIndex)
{
Debug.Log("devices[cameraIndex].name: ");
Debug.Log(devices[cameraIndex].name);
Debug.Log("devices[cameraIndex].isFrontFacing");
Debug.Log(devices[cameraIndex].isFrontFacing);
}
}
else
{
Debug.Log("no webcams found");
}
}
public void SwapCamera()
{
if (WebCamTexture.devices.Length > 0)
{
_currentCameraIndex++;
_currentCameraIndex %= WebCamTexture.devices.Length;
if (_texture != null)
{
StopCamera();
StartCamera();
}
}
}
public void StartCamera()
{
Debug.LogError($"USER PERMISSION {Application.HasUserAuthorization(UserAuthorization.WebCam)}");
Debug.LogError($"DEVICES AMOUNT {WebCamTexture.devices.Length}");
if (WebCamTexture.devices.Length > 0)
{
WebCamDevice device = WebCamTexture.devices[_currentCameraIndex];
_texture = new WebCamTexture(device.name);
_display.texture = _texture;
_texture.Play();
Debug.LogError($"START PLAYING!");
}
}
public void StopCamera()
{
if (_texture != null)
{
_texture.Stop();
_display.texture = null;
_texture = null;
}
}
}
}