Unity调用摄像头获取拍摄画面

using System.Collections;
using UnityEngine;

public class Test : MonoBehaviour
{
    public WebCamTexture cameraTexture;
    public string cameraName = "";

    private string isUser;

    private MeshRenderer renderer;

    void Start()
    {
        renderer = this.GetComponent();

        StartCoroutine(Test1());
    }

    IEnumerator Test1()
    {
        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);

        bool isUser = Application.HasUserAuthorization(UserAuthorization.WebCam);
        isUser = false;

        if (!isUser)
        {
            WebCamDevice[] devices = WebCamTexture.devices;
            cameraName = devices[0].name;
            cameraTexture = new WebCamTexture(cameraName, 1024, 768,30);
            cameraTexture.Play();
            renderer.material.mainTexture = cameraTexture;
        }
    }
}

 

你可能感兴趣的:(Unity)