Unityでスマホのカメラを使う

僕の同僚かつフレンズのid:hiragramがなんかよくわからないカメラアプリを作ってて凄い。

hiragram.hatenablog.jp

僕もそういうのやりたいけどiOS開発やったこと無い。

Unityなら出来る。

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

public class CameraController : MonoBehaviour  {
    public WebCamTexture webCameraTexture = null;
    public GameObject plane;

    // Use this for initialization
    void Start ()
    {
        webCameraTexture = new WebCamTexture ();
        plane.GetComponent<Renderer>().material.mainTexture = webCameraTexture;
        webCameraTexture.Play ();
    }

    // Update is called once per frame
    void Update ()
    {

    }
}

f:id:anoChick:20170323002050p:plain

うつった。 テクスチャに投影してるだけなので↓のようにも出来る。

だからなんだって感じではあるけど、 なんかいろいろできそう。