[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 () 
    {
    
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM