【问题标题】:ARCore cannot detect a button hit inside the canvasARCore 无法检测到画布内的按钮点击
【发布时间】:2018-04-11 20:29:32
【问题描述】:

我必须创建一个在主屏幕内有一个浮动菜单的增强现实应用程序。我正在使用来自 Google 的 ARCore SDK 和 Unity。到目前为止,我已经设法创建了我的菜单并设置了 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;
}

【问题讨论】:

    标签: unity3d button collision-detection augmented-reality arcore


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多