Hit UI elements with raycast in VR,How to make a raycast hit a UI object in VR
I am trying to use a raycast to hit a UI element. The Canvas is attached to the players left hand, and in the right hand is a raycast that is acting as a laser pointer (I am using steamVR 2.0 so there is no built in laser pointers). I want the raycast being sent from the right hand to be able to interact with the canvas on the left. I know there is a graphicRaycast, but as far as I can tell this is only used with the mouse input on the screen. I am using Unity 2018.2.9, and steamvr2.0(my vr headset is the Oculus Rift),I have a canvas with some buttons attatched to one of my vr controllers, and on the other controller I have a raycast shooting out of it. How can I make the raycast interact with the canvas objects? I know there is a graphicRaycaster, but as far as I can tell this is only for getting the mouse input on the screen. I am using SteamVR2 and Unity 2018.2.9
Answer by byrontik_croomo · Nov 08, 2018 at 12:07 PM
maybe this helps, I'm trying to work out the same problem, I noticed buttons need a larger collider cube as in the examples, this may also be required for raycast to hit the collider
For our button to interact with the laser pointer, we need it to have a collider. That colliders size & shape need to match our button. We could do this manually, but to avoid having to resize the collider whenever the button changes, you can use this simple script. from https://unity3d.college/2017/06/17/steamvr-laser-pointer-menus/ ,I'm looking into this also, I had it working with VRTk scripts, switched to SteamVR 2 now to see what works better. Perhaps this helps
For our button to interact with the laser pointer, we need it to have a collider. That colliders size & shape need to match our button. We could do this manually, but to avoid having to resize the collider whenever the button changes, you can use this simple script.
from https://unity3d.college/2017/06/17/steamvr-laser-pointer-menus/
also noticed this plugin for s$$anonymous$$mvr 2, haven't tried it yet https://assetstore.unity.com/packages/tools/gui/vr-uikit-128236