# ウェブブラウザーによるデバイス機能へのアクセス

> Manage browser authorization to access a device feature (webcam).

Unity ウェブプラットフォームは [WebCam へのアクセス](/engine/6000.0/script-reference/unity-engine/web-cam-device.md)をサポートしています。ウェブアプリケーションがデバイス上のウェブカメラにアクセスできるようにするには、ブラウザーでカメラへのアクセスをユーザーにリクエストする必要があります。カメラにアクセスする権限がないと、ブラウザーは不完全または不正確な情報を返します。

**注意**現在、ウェブプラットフォームは WebCam デバイスのみをサポートしています。

ブラウザーでウェブカメラへのアクセス権限をリクエストするには、`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");
        }
    }
}
```

**注意**Unity は、`MediaDevices.getUserMedia()` API を使用して、デバイスにアクセスするためのユーザー権限をリクエストすることを推奨しています。この機能は、セキュアコンテキスト (HTTPS) でのみ使用できます。
