I’m trying to figure out how to get a Web Cam to play on a UI image as I have WAY more control over layout, so far all I have been able to find is how to get a web cam to play on a plane.
Is there a way to get something like this onto a UI.Image that can be positioned onto a canvas?
It’s easy my friend. Use RawImage instead of Image. Add Unlit/Texture material to material property of RawImage. And use this code to play WebCam video on it:
public class PlayMovieTextureOnUI : MonoBehaviour
{
public RawImage rawimage;
void Start ()
{
WebCamTexture webcamTexture = new WebCamTexture();
rawimage.texture = webcamTexture;
rawimage.material.mainTexture = webcamTexture;
webcamTexture.Play();
}
}
Hi @Max-Bot Would you possible be able to help with getting more than one web cam to be accessed?
UPDATE:
Never mind, I figured it out. I tweaked this code to also display a UI Text to display the current camera in use.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class IDwebCams : MonoBehaviour {
public RawImage rawimage;
WebCamTexture webCamTexture;
public Text webCamDisplayText;
void Start ()
{
WebCamDevice[] cam_devices = WebCamTexture.devices;
// for debugging purposes, prints available devices to the console
for (int i = 0; i < cam_devices.Length; i++)
{
print ("Webcam available: " + cam_devices *.name);*