如何为 AR Core 演示设置静态变量并仅实例化一个预制件

How to set static variable and instantiate only one prefab for the AR Core demo

我正在尝试修改 Unity AR Core SDK 中的演示场景并且 我创建了一个静态布尔变量 isCreated 来检查是否创建了 Andy 预制件。

在下面检查

if (Session.Raycast(m_firstPersonCamera.ScreenPointToRay(touch.position), raycastFilter, outHit))

我已将变量设置为 true,然后在此处进行另一个检查

if (Input.touchCount < 1 || (touch = Input.GetTouch (0)).phase != TouchPhase.Began || isCreated) {
    return;
}

但由于某些原因,变量 永远不会设置为 true。 我还注意到日志中的 this error,不禁想知道它是否以某种方式阻止了它的设置。

08-29 14:11:40.564 13392-13407/? E/Unity: OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_ENUM: enum argument out of range
(Filename: ./Runtime/GfxDevice/opengles/GfxDeviceGLES.cpp Line: 368)

请帮忙

我不知道你有多希望你的布尔值变成静态的,但我通过做类似的事情得到了同样的结果:

bool m_placed = false; // under the color array

然后和你一样,我在这里查一下:

if (Session.Raycast(m_firstPersonCamera.ScreenPointToRay(touch.position), raycastFilter, out hit) && !m_placed) {
    ...
    m_placed = true; // At the very end of this block
}

这非常适合我。我没有添加任何东西到

if (Session.Raycast(m_firstPersonCamera.ScreenPointToRay(touch.position), raycastFilter, outHit))

OpenGL 错误是一个已经提出的常见问题。应该不会影响这个。

https://github.com/google-ar/arcore-unity-sdk/issues/3