[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