LoginSignup
19
25

More than 5 years have passed since last update.

UnityのWebCamTexture

Last updated at Posted at 2014-09-12

planeやQuadなどの板ポリにMacやiPhoneなどのカメラ情報を
貼付けるのにwebcamtextureを使うと簡単です。

スクリーンショット 2014-09-12 17.03.20.png

サイズは、publicにして任意に変更できるようにしておきました。
スクリーンショット 2014-09-12 17.03.14.png

こちらが、簡単なスクリプトになります。

WebCameScript
using UnityEngine;
using System.Collections;

public class WebCamScript : MonoBehaviour {
    public int Width = 1920;
    public int Height = 1080;
    public int FPS = 30;

    void Start () {

        var euler = transform.localRotation.eulerAngles;
        transform.localRotation = Quaternion.Euler( euler.x, euler.y, euler.z - 90 );

        var devices = WebCamTexture.devices;
        if (devices.Length > 0)
        {
            var webcamTexture = new WebCamTexture(Width, Height, FPS);
            renderer.material.mainTexture = webcamTexture;
            webcamTexture.Play();
        }else
        {
            Debug.Log("Webカメラが検出できませんでした");
            return;
        }
    }
}


19
25
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
19
25