unity学习—打包apk打开手机摄像头插件Vuforia(非常简单)

34 篇文章 0 订阅

插件下载地址:
链接:https://pan.baidu.com/s/1K3p5dyTNDi8cp8I0HPyOog
提取码:2t4e

下载插件后,拖进场景中

在这里插入图片描述

右键新建  Vuforia Engine—AR Camera

在这里插入图片描述

接下来最重要的一点!点击设置按照下图操作,激活插件,不然会报错!

在这里插入图片描述在这里插入图片描述最后打包就行了!

在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity3D 中,可以使用 WebCamTexture 类来访问摄像头。WebCamTexture 可以从摄像头捕获视频流,并将其作为纹理传递给 Unity3D。以下是在 Unity3D 中打包 WebGL 并调用手机摄像头的步骤: 1. 在 Unity3D 中创建一个新的场景。 2. 在场景中创建一个 Plane 对象,并将其放置在场景中心。 3. 在 Inspector 窗口中,将 Plane 对象的 Scale 设置为 (10, 1, 10)。 4. 在场景中创建一个 Cube 对象,将其放置在 Plane 对象上方,并将其旋转 45 度。 5. 在 Cube 对象上添加一个新的脚本,并将其命名为 WebcamTextureScript。 6. 在脚本中编写以下代码: ``` using UnityEngine; using System.Collections; public class WebcamTextureScript : MonoBehaviour { // The webcam texture private WebCamTexture webcamTexture; // Use this for initialization void Start () { // Get the webcam device WebCamDevice[] devices = WebCamTexture.devices; if (devices.Length > 0) { // Create a new webcam texture webcamTexture = new WebCamTexture(devices[0].name); // Set the texture on the material GetComponent<Renderer>().material.mainTexture = webcamTexture; // Start the webcam webcamTexture.Play(); } } } ``` 7. 在 Unity3D 菜单中选择 File > Build Settings。 8. 在 Build Settings 窗口中,选择 WebGL 平台,并点击 Build 按钮。 9. 在生成的项目目录中,找到 index.html 文件并编辑它。 10. 在文件中找到以下代码: ``` <script src="Build/UnityLoader.js"></script> <script> var gameInstance = UnityLoader.instantiate("gameContainer", "Build/Build.json", {onProgress: UnityProgress}); </script> ``` 11. 在上面的代码后面添加以下代码: ``` <script> navigator.mediaDevices.getUserMedia({video: true}).then(function(stream) { var video = document.querySelector('video'); video.srcObject = stream; video.onloadedmetadata = function(e) { video.play(); }; }).catch(function(err) { console.log(err.name + ": " + err.message); }); </script> ``` 12. 保存并关闭 index.html 文件。 13. 在浏览器中打开 index.html 文件,应该可以看到摄像头的视频流在 Unity3D 场景中。 注意:调用摄像头需要 HTTPS 协议或 localhost 环境。如果您使用的是 localhost 环境,则需要在浏览器中输入 https://localhost:port 打开项目。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值