02-27-2014 07:16 AM
using UnityEngine;
using System.Collections;
public class WebcamTextureScript : MonoBehaviour {
public Material mat;
public GameObject quad;
public GameObject cam;
private WebCamDevice[] devices;
private WebCamTexture texture;
private int current = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if ( texture != null && texture.didUpdateThisFrame )
{
quad.transform.rotation = cam.transform.rotation;
}
if ( Input.GetKeyDown ( "q" ) )
{
devices = WebCamTexture.devices;
if ( texture != null && texture.isPlaying )
texture.Stop ( );
if ( devices.Length > 0 )
{
texture = new WebCamTexture( devices[ current ].name, 768, 480, 60 );
current = ( current + 1 ) % devices.Length;
texture.Play ( );
quad.transform.localScale = new Vector3 ( 25.0f * ( (float)texture.width / (float)texture.height ), 25.0f, 1.0f );
mat.mainTexture = texture;
}
}
}
}
03-17-2014 05:30 AM
03-17-2014 06:54 AM