[Unity3D]unity3d5.0简单的调用摄像头

Unity3D中新建一个工程,加一个Plane,新建一个C# 脚本,将这个脚本添加到Plane上,调用摄像头。(如果显示的图片居然是翻转的,Plane的Rotation 值就可以了)

以下是脚本内容:

using UnityEngine;
using System.Collections;

public class C : MonoBehaviour 
{
    WebCamTexture webcamTexture;
    // Use this for initialization
    void Start () 
    {
        WebCamDevice[] devices = WebCamTexture.devices;
        if (devices.Length > 0)
        {
            webcamTexture = new WebCamTexture(devices[0].name, 320, 240, 25);
       //renderer.material.mainTexture
= webcamTexture;
        //这里和之前版本不一样了
        GetComponent<Render>()
.material.mainTexture = webcamTexture;
            webcamTexture.Play();
        }
    }
    
    // Update is called once per frame
    void Update () 
    {
    
    }
}

 

posted @ 2015-03-18 10:57  南水之源  阅读(4976)  评论(0编辑  收藏  举报