Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created June 21, 2013 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/5828407 to your computer and use it in GitHub Desktop.
Save tsubaki/5828407 to your computer and use it in GitHub Desktop.
webcamのデモ。適当なcubeにアタッチして使う。カメラの初期化に時間がかかるため、SettingFOVは数フレーム待つか毎フレーム呼ぶ必要がある。
using UnityEngine;
using System.Collections;
public class WebCamTextureFOV : MonoBehaviour
{
private WebCamTexture webcam = null;
private bool isPlaying = false;
public bool cameraPositionAuotSetting = true;
void Start ()
{
if (cameraPositionAuotSetting) {
transform.position = Vector3.zero;
Camera.mainCamera.transform.position = Vector3.zero + Vector3.back * 10;
}
}
void OnGUI ()
{
if (!isPlaying) {
if (GUILayout.Button ("camera on", GUILayout.Height (100))) {
CameraOn ();
isPlaying = true;
}
} else {
if (GUILayout.Button ("set FOV", GUILayout.Height (100))) {
SettingFOV ();
}
}
}
void CameraOn ()
{
webcam = new WebCamTexture (WebCamTexture.devices [0].name, 10000, 10000, 15);
renderer.material.mainTexture = webcam;
webcam.Play ();
}
void SettingFOV ()
{
transform.localScale = new Vector3 (webcam.width, webcam.height, 1);
Camera.mainCamera.orthographicSize = webcam.height / 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment