gologiusの巣

プログラミングなどの技術メモです。誰かの役に立てるとうれしいです。

Unity5 Webカメラを使う

ネットに転がってるのでやったら,メモリが足りなかったり?描画順がうまくいかなかったので,自分がやった方法のメモ

これで,画面上にカメラ映像を表示させることができます

using UnityEngine;
using System.Collections;
using System.IO;

public class WebCam : MonoBehaviour {

    public WebCamTexture camTex;
    public Texture2D texture;
    
    public int width = 1280;
    public int height = 800;
    
    GameObject cameraPanel;

    // Use this for initialization
    void Start() {
        camTex = new WebCamTexture(width, height);
    
        cameraPanel = GameObject.Find("CameraPanel");
        
        camTex.Play();
    }
    
    // Update is called once per frame
    void Update() {

        cameraPanel.GetComponent<CanvasRenderer>().SetTexture(camTex);

    }
}

[追記]
対象のGameObjectはUIのRawImageを画面いっぱいに広げたもの.

UIのPlaneなんかでやると,拡大されて?おかしくなる.