webcam on unity?

how to make my webcam work on unity?

Use WebCamTexture.

What I used to make it work the first time :slight_smile:

using UnityEngine;
using System.Collections;

public class Webcam : MonoBehaviour {

  GUITexture tex;
  WebCamTexture camTex;

  void Awake () {

    tex = gameObject.AddComponent<GUITexture>();

    //set up camera
    WebCamDevice[] devices = WebCamTexture.devices;
    Debug.Log("webcam count : "+devices.Length);

    //display list of devices
    for( int i = 0 ; i < devices.Length ; i++ ) {
      Debug.Log("Device:"+devices_.name+ " | IS FRONT FACING:"+devices*.isFrontFacing);*_

}

if(devices.Length <= 0) return;

//10000 will be lowered to actual webcam resolution after Play() is called
camTex = new WebCamTexture(devices[0].name, 10000,10000,60);
camTex.Play();

// width and height are not defined before Play()
Debug.Log("resolution "+camTex.width+“x”+camTex.height);
tex.pixelInset = new Rect(0, -camTex.height * 0.5f,camTex.width, camTex.height);

tex.texture = camTex;

* }*

}