using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Foo {
public class WebCamComponent : MonoBehaviour {
////// Demi-Constructors //////
protected void Start() {
var devices = WebCamTexture.devices;
var validDevices = WebCamTexture
.devices
.Where(x => x.isFrontFacing == this.isUseFrontCamera);
if (validDevices.Count() > 0) {
var webcamTexture = new WebCamTexture(validDevices.First().name);
this.targetMaterial.mainTexture = webcamTexture;
webcamTexture.Play();
}
}
////// Props //////
[SerializeField] private Material targetMaterial = null;
[SerializeField] private bool isUseFrontCamera = false;
////// Methods //////
}
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme