- Home /
Use WebCamTexture with multiple Webcams
Hi, I'm currently working on a project with multiple webcams. I looked at the script reference of WebCamTexture and found out that it uses webcam's device name as parameter to determine which device to manipulate.
But I am using two webcams of the same model, and hence same device name, is there a way to distinguish which camera I am using?
Just discovered that if two webcam with same model is used, one of the webcam's device name will have a number concatenated behind. i.e. CameraName CameraName 1
But still have no idea how to specify which camera will be CameraName and which will be CameraName 1
Anybody figure this out? Would love to have a way to set which texture gets which cam. Thanks!
Answer by Tahair · Sep 20, 2017 at 08:14 AM
Add this script to gameobject. Target1 for showing webcam1 feed, target2 for webcam2. You can use (for example) plane or cube as target1 and target2.
javascript codesnippet:`#pragma strict
private var webcamTexture1 : WebCamTexture; private var webcamTexture2 : WebCamTexture;
var target1 : Transform; var target2 : Transform;
function Start () {
webcamTexture1 = WebCamTexture(); webcamTexture2 = WebCamTexture();
var devices : WebCamDevice[] = WebCamTexture.devices;
if(devices.length > 1){
webcamTexture1.deviceName = devices[0].name;
webcamTexture2.deviceName = devices[1].name;
target1.renderer.material.mainTexture = webcamTexture1;
target2.renderer.material.mainTexture = webcamTexture2;
webcamTexture1.Play();
webcamTexture2.Play();
}
else
print("Make sure you got two cams");
}`
I am in the same situation but I want to select my cameras by a dropdown menu. Is this possible in unity 5.6?
Your answer
Follow this Question
Related Questions
WebcamTexture not refreshing 0 Answers
Web Cam Texture on UI Panel 0 Answers
how to track object motion with webcam 0 Answers