Question by
mindrend · Apr 07, 2017 at 10:10 PM ·
scripting problemprogramming
How do I detect UI Raycasts using the Vive controllers?
So I set it up so that I could look at a UI button and detect it with the HMD. This is what I currently have working:
PointerEventData cursor = new PointerEventData(EventSystem.current);
Camera cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
cursor.position = cam.WorldToScreenPoint(cam.transform.forward + cam.transform.position);
List<RaycastResult> objectsHit = new List<RaycastResult>();
EventSystem.current.RaycastAll(cursor, objectsHit);
int count = objectsHit.Count;
if (count > 0)
{
for (int i = 0; i < count; i++)
{
p(objectsHit[i].gameObject);
}
}
It will display a message when I look at the button in the scene. Now, how do I modify this so that when I point a Vive controller at the button it will display the same message? I can't figure out how to replace the WorldToScreenPoint piece from the HMD camera with something relevant to the Vive controllers.
Any ideas?
Comment