enabling webcam

Hi guys,

not sure which group is more suitable for this, but I was wondering if you could give me directions to how I can possibly activate my webcam connected to the PC.

any help?

Thank, you.
GC.

I was wondering the same thing. i found this code. but i can’t figure out how to make the usb camera actually show up in the raw image area. or even my own image in the raw image window in the lower left corner.
and if you go here Photo Video camera in Unity - Mixed Reality | Microsoft Learn
which is Microsoft stating :
The “WebCam” capability must be declared for an app to use the camera.

  • In the Unity Editor, go to the player settings by navigating to the “Edit > Project Settings > Player” page
  • Select the “Windows Store” tab
  • In the “Publishing Settings > Capabilities” section, check the WebCam and Microphone capabilities

there is no capabilities for windows or anywhere you can check to turn on you live webcam.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class WebcamViewer : MonoBehaviour
{
[Tooltip(“All the found cameras, raw”)]
public WebCamDevice[ ] foundCams;
[Tooltip(“Lazy list for easier camera access”)]
public List cameraList;

private Cam selectedCam;
///


/// Currently selected Camera Cam
///

public Cam SelectedCamera
{
get
{
return selectedCam;
}
set
{
selectedCam = value;
SelectedNewCam();
}
}

[Tooltip(“A single WebCamTexture to always use/reference”)]
public WebCamTexture webcamTexture;
[Tooltip(“RawImage for displaying final image/texture”)]
public RawImage camDisplay;

///


/// Where webcam will be dumped and a copy kept for references
///

private Color32[ ] uneditedImage;
///
/// Active image to be edited
///

private Color32[ ] editedImage;

///


/// Single texture to reuse
///

public Texture2D displayImg;

void Start()
{
//Instantiate and setup
cameraList = new List();
foundCams = WebCamTexture.devices;

//Get RawImage from self
camDisplay = gameObject.GetComponent();

//Setup webcam capture
webcamTexture = new WebCamTexture();

//Put all the cameras into a more nice list with public view
foreach (WebCamDevice webcam in foundCams)
{
cameraList.Add(new Cam(webcam));
}

//If list has more than 1 ior more camera, then put the first in as selected camera
if (cameraList.Count > 0)
{
//Set camera variable
SelectedCamera = cameraList[0];
//Update for new camera being selected
SelectedNewCam();

//Set base editedImage
editedImage = uneditedImage;
//Reverse the complete image
System.Array.Reverse(editedImage);
//Update texture with new image
displayImg.SetPixels32(editedImage);
camDisplay.texture = displayImg;
}
}

///


/// If the selected camera has changed, reset the texture to show other camera
///

private void SelectedNewCam()
{
//Set the new web camera
webcamTexture.name = SelectedCamera.name;

//Update for new webcam resolution, just in case
uneditedImage = new Color32[webcamTexture.width * webcamTexture.height];
editedImage = new Color32[webcamTexture.width * webcamTexture.height];
displayImg = new Texture2D(webcamTexture.width, webcamTexture.height);

//Update the texture display
camDisplay.texture = displayImg;

//Run the webcam
webcamTexture.Play();
}
}

[System.Serializable]
public class Cam
{
public string name;
public WebCamDevice camera;

public Cam(WebCamDevice newCamera)
{
name = newCamera.name;
camera = newCamera;
}
}

i figured it out…use this script( the word webCam is what made my webcam work if it doesn’t work, play with that word) also couldn’t figure out UI Raw Image…i spent forever thinking it was in that…no just use an object and then press play… hope this works for anyone who reads it…

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class CameraScript : MonoBehaviour

{

static WebCamTexture usbCam;

void Start()

{

if (usbCam == null)

usbCam = new WebCamTexture();

GetComponent().material.mainTexture = usbCam;

if (!usbCam.isPlaying)

usbCam.Play();

}

// Update is called once per frame

void Update()

{

}

}

Laptop saya tidak memiliki kamera, bagaimana solusi agar unity tetap bisa berjalan?

LuciousCain
thanks
that is what i was looking for!

Hey there,

Sure, I’d be happy to help! To activate your webcam on your PC, you’ll typically need to install any necessary drivers and then access your webcam through the settings or specific applications like Zoom or Skype.

As for testing your webcam, a convenient and free option is to use https://webcammictest.io/. It’s a straightforward online tool that lets you check your webcam’s functionality in your web browser.

Hope this helps! Let me know if you have any other questions.