WebCam texture doesn't work on Build Windows - Unity 2022.1.17f1

WebCamTexture works fine on editor, but doesn’t work on Build. I have tried: turn off antivirus and firewall, check authorization, put the webcamtexture on UI_RawImage and a plane gameObject, nothing works on build. There is no any real conclusion about the same bug on the forums (many are about Vuforia, and I just want to take a photo by a simple webcam on Windows). Any clues? Below the code. Tks in advance.

using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;
using System.Collections.Generic;

// https://stackoverflow.com/questions/24496438/can-i-take-a-photo-in-unity-using-the-devices-camera

public class GetCam2 : MonoBehaviour
{
    WebCamTexture webCam;    
    //string your_path = "D:\\Lixo\\FotosCam";// any path you want to save your image 
    [SerializeField] string your_path = "";
    public RawImage display;
    public AspectRatioFitter fit;
    public int contadorFotos;
    [SerializeField] GameObject planoWeb;

    IEnumerator Start()
    {
        your_path = "" + Application.dataPath;

        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
        if (Application.HasUserAuthorization(UserAuthorization.WebCam)) {
           LigaCamComeco1();         
        }

    }

    void LigaCamComeco1() {
        if (WebCamTexture.devices.Length == 0)
        {
            Debug.LogError("can not found any camera!");
            return;
        }
        int index = -1;
        for (int i = 0; i < WebCamTexture.devices.Length; i++)
        {
            if (WebCamTexture.devices*.name.ToLower().Contains("pc"))*

{
Debug.Log(“WebCam Name:” + WebCamTexture.devices*.name + " Webcam Index:" + i);*
index = i;
}
}

if (index == -1)
{
Debug.LogError(“can not found your camera name!”);
return;
}

WebCamDevice device = WebCamTexture.devices[index];
webCam = new WebCamTexture(device.name);
webCam.Play();
display.texture = webCam;
planoWeb.GetComponent().materials[0].mainTexture = webCam;
}

public void Update()
{
if (Input.GetKeyDown(KeyCode.PageUp)) {
Ratio();
callTakePhoto();
}
}

void Ratio() {
float ratio = (float)webCam.width / (float)webCam.height;
fit.aspectRatio = ratio;

float ScaleY = webCam.videoVerticallyMirrored ? -1f : 1f;
display.rectTransform.localScale = new Vector3(1f, ScaleY, 1f);

int orient = -webCam.videoRotationAngle;
display.rectTransform.localEulerAngles = new Vector3(0, 0, orient);
}

public void callTakePhoto() // call this function in button click event
{
StartCoroutine(TakePhoto());
}
IEnumerator TakePhoto() // Start this Coroutine on some button click
{
yield return new WaitForEndOfFrame();

Texture2D photo = new Texture2D(webCam.width, webCam.height);
photo.SetPixels(webCam.GetPixels());
photo.Apply();

byte[] bytes = photo.EncodeToJPG();
File.WriteAllBytes(your_path + “\ZaxisCam” + contadorFotos + “.jpg”, bytes);
contadorFotos++;

}
}

Sorry, the problem has nothing about Unity. I just had to change ESET configuration, turn off webcam protection

Hello, I have the same problem, my webcam is all black. Try updating unity. I tried to run it on Windows 10 thinking it was a camera permissions problem. Try setting it to super low quality. I thought it was the opencv library. Tomorrow I will try to deactivate Kasperky. Please some extra solution.