Legacy Documentation: Version 2017.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Application.RequestUserAuthorization

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function RequestUserAuthorization(mode: UserAuthorization): AsyncOperation;
public static AsyncOperation RequestUserAuthorization(UserAuthorization mode);

Description

Request authorization to use the webcam or microphone in the Web Player.

For security reasons we require you to have the user explicitly allow these features in the web player. To do so, you need to call Application.RequestUserAuthorization, which shows a dialog box to the user, and wait for operation to complete before being able to use these features. Use Application.HasUserAuthorization to query the result of the operation.

function Start() {
    // Request permission to use both webcam and microphone.
    yield Application.RequestUserAuthorization (UserAuthorization.WebCam | UserAuthorization.Microphone);

if (Application.HasUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone)) { // we got permission. Set up webcam and microphone here. } else { // no permission. Show error here. } }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { IEnumerator Start() { yield return Application.RequestUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone); if (Application.HasUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone)) { } else { } } }

Note: The web player is not supported from 5.4.0 onwards.

Did you find this page useful? Please give it a rating: