I need some help with raycasting UI with Daydream. As there are only a demo for gameObjects (cubes), I want to know I can handle UI elements. The UI elements should react as usual, I mean highlighted and so on. The posts in How to use Graphic Raycaster with WorldSpace UI? were helpful, but completely.
I used DrawRay to see where my pointer is actually going through and it works good. But no log message is created.
void Update()
{
Quaternion ori = GvrController.Orientation;
Vector3 vector = ori * Vector3.forward;
Debug.DrawRay(transform.position, vector * 100000, Color.green);
PointerEventData pointerData = new PointerEventData(null);
pointerData.position = vector;
Debug.Log(vector);
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
if (results.Count > 0)
{
Debug.Log(results[0]);
}
}
Canvas (World Space) and Button is created as useal and not modified.
In your case I see two problems :
PointerEventData pointerData = new PointerEventData(EventSystem.current);
insted of PointerEventData pointerData = new PointerEventData(null);
PointerEventData.position
is a Vector2 and not a Vector3 : you should try pointerData.position = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);
As a side note you can use graphicRaycaster.Raycast(pointerData, results);
where graphicRaycaster is public and you assign it the GraphicRaycaster component of you Canvas .
这个有用的方法怎么样:
Vector3 CurrentRaycastResultWorldPosition = GvrPointerInputModule.Pointer.CurrentRaycastResult.worldPosition;
根据您的问题 raycasting world space UI,如果您使用的是 google cardbard 或 daydream,那么您应该尝试将脚本 gvrgraphicphysics raycaster 附加到 UI 画布。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.