# WebCamTexture

> WebCam Textures are textures onto which the live video input is rendered.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.AudioModule
* **Inherits from:** [Texture](/engine/6000.0/script-reference/unityengine/texture.md)

```csharp
public sealed class WebCamTexture : Texture
```

## Remarks

On Android, iOS, and WebGL platforms, `WebCamTexture` requires the camera permission. On Android, you can request it at runtime using the [Permission](/engine/6000.0/script-reference/unityengine/android/permission.md) API. For more information, refer to [Request runtime permissions](/engine/6000.0/manual/platform-specific/android/developing/device-features-and-permissions/requesting-permissions.md) documentation.

On iOS and WebGL, you can request camera permission at runtime using [Application.RequestUserAuthorization](/engine/6000.0/script-reference/unityengine/application/requestuserauthorization.md).

**Note**: On Android and iOS platforms, Unity doesn't support multiple WebCamTextures simultaneously.

The following code example demonstrates how to request the user for camera permission on iOS, Android, and WebGL platforms.

## Examples

```csharp
using UnityEngine;
using System;
using System.Collections;
using UnityEngine;
#if UNITY_ANDROID
using UnityEngine.Android;
#endif

public class WebCam : MonoBehaviour
{
#if UNITY_IOS || UNITY_WEBGL
    private bool CheckPermissionAndRaiseCallbackIfGranted(UserAuthorization authenticationType, Action authenticationGrantedAction)
    {
        if (Application.HasUserAuthorization(authenticationType))
        {
            if (authenticationGrantedAction != null)
                authenticationGrantedAction();

            return true;
        }
        return false;
    }

    private IEnumerator AskForPermissionIfRequired(UserAuthorization authenticationType, Action authenticationGrantedAction)
    {
        if (!CheckPermissionAndRaiseCallbackIfGranted(authenticationType, authenticationGrantedAction))
        {
            yield return Application.RequestUserAuthorization(authenticationType);
            if (!CheckPermissionAndRaiseCallbackIfGranted(authenticationType, authenticationGrantedAction))
                Debug.LogWarning($"Permission {authenticationType} Denied");
        }
    }
#elif UNITY_ANDROID
    private void PermissionCallbacksPermissionGranted(string permissionName)
    {
        StartCoroutine(DelayedCameraInitialization());
    }

    private IEnumerator DelayedCameraInitialization()
    {
        yield return null;
        InitializeCamera();
    }

    private void PermissionCallbacksPermissionDenied(string permissionName)
    {
        Debug.LogWarning($"Permission {permissionName} Denied");
    }

    private void AskCameraPermission()
    {
        var callbacks = new PermissionCallbacks();
        callbacks.PermissionDenied += PermissionCallbacksPermissionDenied;
        callbacks.PermissionGranted += PermissionCallbacksPermissionGranted;
        Permission.RequestUserPermission(Permission.Camera, callbacks);
    }
#endif

    void Start()
    {
#if UNITY_IOS || UNITY_WEBGL
        StartCoroutine(AskForPermissionIfRequired(UserAuthorization.WebCam, () => { InitializeCamera(); }));
        return;
#elif UNITY_ANDROID
        if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
        {
            AskCameraPermission();
            return;
        }
#endif
        InitializeCamera();
    }

    private void InitializeCamera()
    {
        WebCamTexture webcamTexture = new WebCamTexture();
        Renderer renderer = GetComponent<Renderer>();
        renderer.material.mainTexture = webcamTexture;
        webcamTexture.Play();
    }
}
```

## Constructors

| Constructor                                                                                                                                                                  | Description             |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| [WebCamTexture()](/engine/6000.0/script-reference/unityengine/webcamtexture/ctor.md#webcamtexture\(\))                                                                       | Create a WebCamTexture. |
| [WebCamTexture(System.Int32,System.Int32)](/engine/6000.0/script-reference/unityengine/webcamtexture/ctor.md#webcamtexture\(int-int\))                                       | Create a WebCamTexture. |
| [WebCamTexture(System.Int32,System.Int32,System.Int32)](/engine/6000.0/script-reference/unityengine/webcamtexture/ctor.md#webcamtexture\(int-int-int\))                      | Create a WebCamTexture. |
| [WebCamTexture(System.String)](/engine/6000.0/script-reference/unityengine/webcamtexture/ctor.md#webcamtexture\(string\))                                                    | Create a WebCamTexture. |
| [WebCamTexture(System.String,System.Int32,System.Int32)](/engine/6000.0/script-reference/unityengine/webcamtexture/ctor.md#webcamtexture\(string-int-int\))                  | Create a WebCamTexture. |
| [WebCamTexture(System.String,System.Int32,System.Int32,System.Int32)](/engine/6000.0/script-reference/unityengine/webcamtexture/ctor.md#webcamtexture\(string-int-int-int\)) | Create a WebCamTexture. |

## Properties

| Property                                                                                                        | Description                                                                                                                         |
| --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| [autoFocusPoint](/engine/6000.0/script-reference/unityengine/webcamtexture/autofocuspoint.md)                   | This property allows you to set/get the auto focus point of the camera. This works only on **Android** and **iOS** devices.         |
| [deviceName](/engine/6000.0/script-reference/unityengine/webcamtexture/devicename.md)                           | Set this to specify the name of the device to use.                                                                                  |
| [didUpdateThisFrame](/engine/6000.0/script-reference/unityengine/webcamtexture/didupdatethisframe.md)           | Did the video buffer update this frame?                                                                                             |
| [isDepth](/engine/6000.0/script-reference/unityengine/webcamtexture/isdepth.md)                                 | This property is true if the texture is based on depth data.                                                                        |
| [isPlaying](/engine/6000.0/script-reference/unityengine/webcamtexture/isplaying.md)                             | Returns if the camera is currently playing.                                                                                         |
| [requestedFPS](/engine/6000.0/script-reference/unityengine/webcamtexture/requestedfps.md)                       | Set the requested frame rate of the camera device (in frames per second).                                                           |
| [requestedHeight](/engine/6000.0/script-reference/unityengine/webcamtexture/requestedheight.md)                 | Set the requested height of the camera device.                                                                                      |
| [requestedWidth](/engine/6000.0/script-reference/unityengine/webcamtexture/requestedwidth.md)                   | Set the requested width of the camera device.                                                                                       |
| [videoRotationAngle](/engine/6000.0/script-reference/unityengine/webcamtexture/videorotationangle.md)           | Returns an clockwise angle (in degrees), which can be used to rotate a polygon so camera contents are shown in correct orientation. |
| [videoVerticallyMirrored](/engine/6000.0/script-reference/unityengine/webcamtexture/videoverticallymirrored.md) | Returns if the texture image is vertically flipped.                                                                                 |

## Static Properties

| Property                                                                        | Description                         |
| ------------------------------------------------------------------------------- | ----------------------------------- |
| [devices](/engine/6000.0/script-reference/unityengine/webcamtexture/devices.md) | Return a list of available devices. |

## Methods

| Method                                                                                  | Description                                                                                                                |
| --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| [GetPixel](/engine/6000.0/script-reference/unityengine/webcamtexture/getpixel.md)       | Gets the pixel color at coordinates (`x`, `y`).                                                                            |
| [GetPixels](/engine/6000.0/script-reference/unityengine/webcamtexture/getpixels.md)     | Gets the pixel color data for a mipmap level as [Color](/engine/6000.0/script-reference/unityengine/color.md) structs.     |
| [GetPixels32](/engine/6000.0/script-reference/unityengine/webcamtexture/getpixels32.md) | Gets the pixel color data for a mipmap level as [Color32](/engine/6000.0/script-reference/unityengine/color32.md) structs. |
| [Pause](/engine/6000.0/script-reference/unityengine/webcamtexture/pause.md)             | Pauses the camera.                                                                                                         |
| [Play](/engine/6000.0/script-reference/unityengine/webcamtexture/play.md)               | Starts the camera.                                                                                                         |
| [Stop](/engine/6000.0/script-reference/unityengine/webcamtexture/stop.md)               | Stops the camera.                                                                                                          |

## Inheritance

**Inherited Members:**

* [Texture.GenerateAllMips()](/engine/6000.0/script-reference/unityengine/texture/generateallmips.md)
* [Texture.SetGlobalAnisotropicFilteringLimits(int, int)](/engine/6000.0/script-reference/unityengine/texture/setglobalanisotropicfilteringlimits.md)
* [Texture.GetNativeTexturePtr()](/engine/6000.0/script-reference/unityengine/texture/getnativetextureptr.md)
* [Texture.IncrementUpdateCount()](/engine/6000.0/script-reference/unityengine/texture/incrementupdatecount.md)
* [Texture.SetStreamingTextureMaterialDebugProperties()](/engine/6000.0/script-reference/unityengine/texture/setstreamingtexturematerialdebugproperties.md#setstreamingtexturematerialdebugproperties\(\))
* [Texture.SetStreamingTextureMaterialDebugProperties(int)](/engine/6000.0/script-reference/unityengine/texture/setstreamingtexturematerialdebugproperties.md#setstreamingtexturematerialdebugproperties\(int\))
* [Texture.mipmapCount](/engine/6000.0/script-reference/unityengine/texture/mipmapcount.md)
* [Texture.graphicsFormat](/engine/6000.0/script-reference/unityengine/texture/graphicsformat.md)
* [Texture.width](/engine/6000.0/script-reference/unityengine/texture/width.md)
* [Texture.height](/engine/6000.0/script-reference/unityengine/texture/height.md)
* [Texture.dimension](/engine/6000.0/script-reference/unityengine/texture/dimension.md)
* [Texture.isReadable](/engine/6000.0/script-reference/unityengine/texture/isreadable.md)
* [Texture.wrapMode](/engine/6000.0/script-reference/unityengine/texture/wrapmode.md)
* [Texture.wrapModeU](/engine/6000.0/script-reference/unityengine/texture/wrapmodeu.md)
* [Texture.wrapModeV](/engine/6000.0/script-reference/unityengine/texture/wrapmodev.md)
* [Texture.wrapModeW](/engine/6000.0/script-reference/unityengine/texture/wrapmodew.md)
* [Texture.filterMode](/engine/6000.0/script-reference/unityengine/texture/filtermode.md)
* [Texture.anisoLevel](/engine/6000.0/script-reference/unityengine/texture/anisolevel.md)
* [Texture.mipMapBias](/engine/6000.0/script-reference/unityengine/texture/mipmapbias.md)
* [Texture.updateCount](/engine/6000.0/script-reference/unityengine/texture/updatecount.md)
* [Texture.isDataSRGB](/engine/6000.0/script-reference/unityengine/texture/isdatasrgb.md)
* [Texture.imageContentsHash](/engine/6000.0/script-reference/unityengine/texture/imagecontentshash.md)
* [Texture.totalTextureMemory](/engine/6000.0/script-reference/unityengine/texture/totaltexturememory.md)
* [Texture.desiredTextureMemory](/engine/6000.0/script-reference/unityengine/texture/desiredtexturememory.md)
* [Texture.targetTextureMemory](/engine/6000.0/script-reference/unityengine/texture/targettexturememory.md)
* [Texture.currentTextureMemory](/engine/6000.0/script-reference/unityengine/texture/currenttexturememory.md)
* [Texture.nonStreamingTextureMemory](/engine/6000.0/script-reference/unityengine/texture/nonstreamingtexturememory.md)
* [Texture.streamingMipmapUploadCount](/engine/6000.0/script-reference/unityengine/texture/streamingmipmapuploadcount.md)
* [Texture.streamingRendererCount](/engine/6000.0/script-reference/unityengine/texture/streamingrenderercount.md)
* [Texture.streamingTextureCount](/engine/6000.0/script-reference/unityengine/texture/streamingtexturecount.md)
* [Texture.nonStreamingTextureCount](/engine/6000.0/script-reference/unityengine/texture/nonstreamingtexturecount.md)
* [Texture.streamingTexturePendingLoadCount](/engine/6000.0/script-reference/unityengine/texture/streamingtexturependingloadcount.md)
* [Texture.streamingTextureLoadingCount](/engine/6000.0/script-reference/unityengine/texture/streamingtextureloadingcount.md)
* [Texture.streamingTextureForceLoadAll](/engine/6000.0/script-reference/unityengine/texture/streamingtextureforceloadall.md)
* [Texture.streamingTextureDiscardUnusedMips](/engine/6000.0/script-reference/unityengine/texture/streamingtexturediscardunusedmips.md)
* [Texture.allowThreadedTextureCreation](/engine/6000.0/script-reference/unityengine/texture/allowthreadedtexturecreation.md)
* [Texture.graphicsTexture](/engine/6000.0/script-reference/unityengine/texture/graphicstexture.md)
* [Object.GetInstanceID()](/engine/6000.0/script-reference/unityengine/object/getinstanceid.md)
* [Object.GetHashCode()](/engine/6000.0/script-reference/unityengine/object/gethashcode.md)
* [Object.InstantiateAsync\<T>(T)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.Instantiate(Object, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion\))
* [Object.Instantiate(Object, Vector3, Quaternion, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion-transform\))
* [Object.Instantiate(Object)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object\))
* [Object.Instantiate(Object, Scene)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-scene\))
* [Object.Instantiate\<T>(T, InstantiateParameters)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, InstantiateParameters)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate(Object, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform\))
* [Object.Instantiate(Object, Transform, bool)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform-bool\))
* [Object.Instantiate\<T>(T)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform, bool)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Destroy(Object, float)](/engine/6000.0/script-reference/unityengine/object/destroy.md)
* [Object.DestroyImmediate(Object, bool)](/engine/6000.0/script-reference/unityengine/object/destroyimmediate.md)
* [Object.FindObjectsByType(Type, FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectssortmode\))
* [Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectsinactive-findobjectssortmode\))
* [Object.DontDestroyOnLoad(Object)](/engine/6000.0/script-reference/unityengine/object/dontdestroyonload.md)
* [Object.FindObjectsByType\<T>(FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectssortmode\))
* [Object.FindObjectsByType\<T>(FindObjectsInactive, FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectsinactive-findobjectssortmode\))
* [Object.FindFirstObjectByType\<T>()](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytypet\(\))
* [Object.FindAnyObjectByType\<T>()](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(\))
* [Object.FindFirstObjectByType\<T>(FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytypet\(findobjectsinactive\))
* [Object.FindAnyObjectByType\<T>(FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(findobjectsinactive\))
* [Object.FindFirstObjectByType(Type)](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytype\(type\))
* [Object.FindAnyObjectByType(Type)](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type\))
* [Object.FindFirstObjectByType(Type, FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytype\(type-findobjectsinactive\))
* [Object.FindAnyObjectByType(Type, FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type-findobjectsinactive\))
* [Object.ToString()](/engine/6000.0/script-reference/unityengine/object/tostring.md)
* [Object.name](/engine/6000.0/script-reference/unityengine/object/name.md)
* [Object.hideFlags](/engine/6000.0/script-reference/unityengine/object/hideflags.md)

### Operators

| Operator                                                                           | Description                                                             |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [operator ==](/engine/6000.0/script-reference/unityengine/object/op-equality.md)   | Compares two object references to see if they refer to the same object. |
| [bool](/engine/6000.0/script-reference/unityengine/object/op-implicit.md)          | Determines whether the object exists.                                   |
| [operator !=](/engine/6000.0/script-reference/unityengine/object/op-inequality.md) | Compares if two objects refer to a different object.                    |
