【发布时间】: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