- Home /
Question by
sylvie_ · Mar 16, 2017 at 04:56 AM ·
camerawebcamtexturewebcam
webcam Capture from webcam encountered: IndexOutOfRangeException: Array index is out of range
I 'm trying to call the webcam from the plane object, and planning to capture the image from there. But my class library encountered an error
"IndexOutOfRangeException: Array index is out of range."
Just a simple code, yet I failed to figure out why.
public class CameraCapture : MonoBehaviour {
private WebCamTexture webcamTexture;
private Texture2D textureImg;
private int imgWidth = 640;
private int imgHeight = 480;
private GameObject plane;
private Texture2D videoTexture;
private Texture2D tmp;
void Start () {
WebCamDevice[] devices = WebCamTexture.devices;
Debug.Log("devices"+ devices.Length);
videoTexture = new Texture2D(imgWidth, imgHeight, TextureFormat.RGB24, false);
tmp = new Texture2D(imgWidth, imgHeight, TextureFormat.RGB24, false);
textureImg = new Texture2D(imgWidth, imgHeight, TextureFormat.RGB24, false);
webcamTexture = new WebCamTexture(devices[1].name, imgWidth, imgHeight, 60);
webcamTexture.Play();
plane = GameObject.Find("Plane");
} }
Any advice ? thanks in advance.
Comment
which line is throwing the exception? maybe try using the first device at index 0: device[0]
Your answer
Follow this Question
Related Questions
Use one webcamtexture on multiple gameobject 0 Answers
How to simultaneously render multiple (web)cam streams in Android 1 Answer
How do I adjust the brightness, color and contrast using a slider? 0 Answers
,iOS WebCamera Texture GetPixels() call returns only black colours? 1 Answer
WebCamTexture.devices.Length returning 0 in Unity 2020.3.8f1 0 Answers