打开相机

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Exclaiming/article/details/80357545
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cameraView : MonoBehaviour
{

    public GameObject cameraViewPlan;

    public static Texture2D viewTexture;
    public static WebCamTexture viewTextureCamera;

    // Use this for initialization
    void Start()
    {

        WebCamDevice[] devices = WebCamTexture.devices;
        viewTextureCamera = new WebCamTexture("Logitech HD Webcam C310", 640, 480, 30);//更改相机名称
        viewTextureCamera.Play();


    }

    // Update is called once per frame
    void Update()
    {

        viewTexture = new Texture2D(viewTextureCamera.width, viewTextureCamera.height);
        viewTexture.SetPixels(viewTextureCamera.GetPixels());
        viewTexture.Apply();

        GetComponent<Renderer>().material.mainTexture = viewTexture;
    }
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页