Created
May 4, 2016 03:00
-
-
Save tuti107/c83f1ae3dfa5c5c3f19f7ac346e3d48c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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