Skip to content

Instantly share code, notes, and snippets.

@tuti107
Created May 4, 2016 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuti107/c83f1ae3dfa5c5c3f19f7ac346e3d48c to your computer and use it in GitHub Desktop.
Save tuti107/c83f1ae3dfa5c5c3f19f7ac346e3d48c to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class WebCameraController : MonoBehaviour
{
public int Width = 1280;
public int Height = 720;
public int FPS = 30;
public int camIndex = 0;
void Start()
{
WebCamDevice[] devices = WebCamTexture.devices;
if (devices != null && devices.Length > camIndex)
{
// display all cameras
for (var i = 0; i < devices.Length; i++)
{
Debug.Log(devices[i].name);
}
WebCamTexture webcamTexture = new WebCamTexture(devices[camIndex].name, Width, Height, FPS);
GetComponent<Renderer>().material.mainTexture = webcamTexture;
webcamTexture.Play();
}
else
{
Debug.Log("bad index:" + camIndex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment