I'm a beginner of Unity and I've been trying to make an app for the Oculus go. So I implemented the Oculus go Controller working and some buttons on the screen. I can click the buttons and call the functions connected to the buttons. What I wanna do is I want to trigger some action when the controller clicked on not UI buttons.
I've tried these methods but I got false every time even if the button shows highlight color when the pointer is on the button.
Physics.Raycast(..)
EventSystem.current.IsPointerOverGameObject
Ray laserPointer = new Ray(rightHandAnchor.position, rightHandAnchor.forward);
RaycastHit hit;
bool hitOrNot = Physics.Raycast(laserPointer, out hit, maxRayDistance);
and
bool hitOrNot = EventSystem.current.IsPointerOverGameObject;
You need to have the
OVRInputModulein your scene'sEventSystemobject (you can delete the "Standard Input Module".This will allow the laser pointer to interface with the
UIsystem using standard-like events.The other thing to note is in order for your laser pointer to interact with normal game objects (non-UI), you must add the
OVRPhysicsRaycasterto yourOVRCameraRigobject in your scene.For the
OVRInputModule, you will need set the "Ray Transform" property to either therightHandAnchororleftHandAnchorin yourLocalAvatarobject.EDIT:
I forgot to mention that your canvas(es) need to have the
OVRRaycastercomponent added as well. TheOVRInputModulewill basically overload all the normal input events, so your canvas buttons will respond toIPointerEnterHandlerevents just like they would if you were using a mouse.With all of this you shouldn't really need to manually do raycasting in your script unless you have special needs for it.
Furthermore, whatever "Event Mask" you select for your
OVRPhysicsRaycasterin the camera rig, any normal (non-UI) 3D object that is in that layer will detect the sameIPointerEnterHandlerandIPointer...Handlerevents just like a UI button, so you can use the same code for those objects as well, not just the UI objects.