ARCore 无法检测到 canvas 内的按钮点击

ARCore cannot detect a button hit inside the canvas

好吧,我必须创建这个增强现实应用程序,它在主屏幕内有一个浮动菜单。我在 Unity 中使用 Google 的 ARCore SDK。到目前为止,我已经设法创建了我的菜单并设置了 ARCore 摄像头,这样我就可以在使用设备摄像头渲染背景时正确查看菜单。因此无法单击该按钮,我已尝试使用 RayCasting 到带有对撞机的按钮上,但这也不起作用。我是 Unity 游戏开发的新手,谢谢。

我试过的代码是这样的,它适用于游戏对象,但不适用于 UI 元素。

//Code from Google's example
if (Input.touchCount< 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
{
    return;
}
//My Code
Debug.Log("Touched");


Ray ray = FirstPersonCamera.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hitObject;
if(Physics.Raycast(ray,out hitObject, Mathf.Infinity))
{
    Debug.Log(hitObject.transform.name);
    Debug.Log(hitObject.collider.name);
    return;
}

您是否已经看过 Unity onclick 按钮文档? https://docs.unity3d.com/ScriptReference/UI.Button-onClick.html

好的,看来答案很简单。我的按钮和通常的 UI 没有交互的原因是因为我没有在 canvas 上看到选项 Event Camera。一旦我在 canvas 事件相机中添加来自 AR Core 的第一人称相机,一切就开始工作了。 Canvas setting picture