2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WebCamTexture を最小限で使うクラス

Last updated at Posted at 2018-02-27
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 //////
	}
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?