Version: Unity 6 Beta (6000.0)
Language : English
Configure a Web Canvas size
Web networking

Web browser access to device features

The Unity Web platform supports WebCam access. To allow a Web application to access the webcam on a device, the browser must request its user to provide access to the cameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary
. Without the permission to access the camera, the browser returns incomplete or inaccurate information.

Note: Currently, the Web platform supports WebCam devices only.

To request browser permission to access the webcam, use the Application.RequestUserAuthorization API:

using UnityEngine;
using UnityEngine.iOS;
using System.Collections;

// Get WebCam information from the browser
public class ExampleClass : MonoBehaviour
{
    private WebCamDevice[] devices;
    
    // Use this for initialization
    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");
        }
    }
}

Note: Unity recommends to use the MediaDevices.getUserMedia() API to request user permission for accessing the device. This feature is available only in secure contexts (HTTPS).

Configure a Web Canvas size
Web networking
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961