Search Unity

How to Drag Slider With Finger

Discussion in 'AR/VR (XR) Discussion' started by tuf91497, Aug 15, 2018.

  1. tuf91497

    tuf91497

    Joined:
    May 21, 2018
    Posts:
    13
    I'm making a menu system for my VR game. The menu is sized in worldspace and you pick it up like a clipboard. I'm using an Oculus, but this solution probably doesn't have much reliance on the Oculus SDK. I have the menu set up so that buttons have a trigger box collider on them, and I add a tiny trigger sphere collider to the tip of both index fingers of the Oculus LocalAvatar. Then I use OnTriggerEnter() to add functions to the buttons as I need. This way I can press buttons with my finger. I have gotten this to work with toggles, so I can switch toggles on/off by pressing with my finger as well.

    Now I need to add functionality for sliders. My thought was to add a trigger box collider to the handle of the slider and to somehow use an onTriggerEnter to change the handle position.

    Is there an easier way to do this? Can I instigate a Drag event with OnTriggerEnter, and somehow link that to the position of my finger?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    You're working way too hard. Set up an EventSystem input module to use the oculus controller instead of a mouse, and all your UI will Just Work™️.

    The Oculus SDK actually includes such an event system script, and the demo scenes show it in use. Or if you want to do it yourself (which is not too hard), start here.