using
1using System; 2using System.Collections; 3using UnityEngine.UI; 4 5public class WebCam : MonoBehaviour { 6 public Camera maincamera; 7 WebCamTexture webcamTexture; 8 const int FPS = 60; 9 10 void Start(){ 11 //Quadを画面いっぱいに広げる 12 float _h = maincamera.orthographicSize * 2; 13 float _w = _h * maincamera.aspect; 14 //スマホ(Unity)が横ならそのまま 15 if(Input.deviceOrientation == DeviceOrientation.LandscapeLeft){ 16 transform.localScale = new Vector3 (_w, _h, 1); 17 } 18 //縦なら回転させる 19 if(Input.deviceOrientation == DeviceOrientation.FaceUp){ 20 transform.localScale = new Vector3 (_h, _w, 1); 21 transform.localRotation *= Quaternion.Euler(0,0,-90); 22 } 23 //カメラのテクスチャをQuadに載せる 24 Renderer rend = GetComponent<Renderer>(); 25 if(WebCamTexture.devices.Length > 0){ 26 WebCamDevice cam = WebCamTexture.devices[0]; 27 WebCamTexture wcam = new WebCamTexture (cam.name); 28 wcam.Play (); 29 int width = wcam.width, height = wcam.height; 30 if(width<1280||height<720){width*=2;height*=2;} 31 webcamTexture = new WebCamTexture (cam.name, width, height, FPS); 32 wcam.Stop (); 33 34 rend.material.mainTexture = webcamTexture; 35 webcamTexture.Play(); 36 } 37 } 38} 39コード
Quadにカメラ画面を映し出すというすくりぷとなのですが、画像のようにQuadの枠内のみにしか表示されません。
原因は一体何なのでしょうか?
Quadにカメラ画面を映すのだから、Quadの中にしか描画されないのは当然だと思うんですが…?
回答1件
あなたの回答
tips
プレビュー