如何在Unity中完全重置ARKit场景 [英] How to completely reset an ARKit scene in Unity

查看:184
本文介绍了如何在Unity中完全重置ARKit场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我在ARKit和Unity方面遇到了一个小问题.

Hey guys I'm having a small issue with ARKit and Unity.

在我制作的游戏中,当玩家死亡时,我正在重新加载场景,但是当重新加载场景时,所有GameObjects仍与上一个会话处于相同位置.我希望我的所有对象在重新加载场景时都能返回到它们的起始位置.

In the game that I'm making I'm reloading my scene when the player dies, however when the scene is reloaded all the GameObjects are still in the same position from the last session. I want all my objects to return to their starting positions when the scene is reloaded.

我看到一些关于位置和旋转的变量在代码中被标记为静态".我尝试更改它们,但遇到很多编译错误.

I saw that some variables regarding position and rotation are marked as "static" in the code. I tried changing them but I got a lot of compile errors.

有人知道解决这个问题的方法吗?

Does anyone know a way around this?

推荐答案

我找到了解决方案!

在!UnityEditor"部分的ARCameraManager脚本中添加以下代码行.

Add these lines of code in your ARCameraManager script in the "!UnityEditor" part.

UnityARSessionRunOption options = new UnityARSessionRunOption();
options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
m_session.RunWithConfigAndOptions(config, options);

现在,每次重新加载场景时,所有AR元素(平面,锚点,摄像机跟踪数据)都将重置.

Now every time you reload your scene all AR elements (planes, anchors, camera tracking data) are reset.

这篇关于如何在Unity中完全重置ARKit场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆