【发布时间】:2018-10-10 09:34:06
【问题描述】:
我有 Unity3D 2017 的基本 webgl 应用程序,我使用网络摄像头纹理在屏幕上显示网络摄像头源。这是我用来请求网络摄像头权限的代码:
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
Debug.Log("webcam found");
startWebCam ();
}
else
{
Debug.Log("webcam not found");
}
这是在用户看到的平面上呈现网络摄像头提要的代码。
void startWebCam() {
WebCamDevice device = WebCamTexture.devices[0];
cam_texture = new WebCamTexture (device.name);
camera_renderer.material.mainTexture = cam_texture;
cam_texture.Play ();
}
它在编辑器中工作正常,但在我导出 webgl 构建时不起作用。它确实要求允许使用网络摄像头,然后我的笔记本电脑摄像头旁边的绿灯亮起,但我只能看到黑屏。但是,有一次我认为我刷新了两次或其他什么,出现了网络摄像头提要。之后我就无法重现它了。
在此不胜感激。谢谢。
【问题讨论】:
标签: unity3d webcam unity-webgl