u3d的摄像头:WebCamTexture

OpenCamera的调用不要放在Awake中

void Start()
{
        StartCoroutine(<span style="font-family: Arial, Helvetica, sans-serif;">OpenCamera</span>());
}
	IEnumerator OpenCamera()
    {
        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);//授权
        if (Application.HasUserAuthorization(UserAuthorization.WebCam))
        {
            WebCamDevice[] devices = WebCamTexture.devices;
            if (devices.Length <= 0)
            {
                Debug.Log("你的设备没有摄像头!!!");
                isOpneCam = false;
                yield break;
            }
            isOpneCam = true;
            string deviceName = devices[0].name;
            // 宽高互换
            camTex = new WebCamTexture(deviceName, (int)(Screen.height), (int)(Screen.width), 12);

            camTex.Play();//开始摄像
            rimg_ShowCamera.texture = camTex;

           
        }
        yield return null;
    }

你可能感兴趣的:(unity,摄像头,AnYuanLzh,WebCamTexture)