Search Unity

Help with Vive Grip Button

Discussion in 'VR' started by agsears, Sep 15, 2019.

  1. agsears

    agsears

    Joined:
    Sep 4, 2019
    Posts:
    1
    Help!

    I have spent a great deal of time trying to reliably get access to the Vive Grip buttons. Can anybody tell me a reliable way to attach the Grip buttons to a script so that I can attach my necessary routines to them?

    All the online code I have found has either been outdated or outright incorrect and I am about to pull all my hair out.

    Any help would be greatly appreciated.

    Alexa
     
  2. Aholio

    Aholio

    Joined:
    Sep 15, 2019
    Posts:
    2
    Hey Alexa, this is how it got it working. Just at this to the Update() method in the script you are using to handle the controller.

    Code (CSharp):
    1. void Update()
    2. {
    3.     var rightHandDevices = new List<UnityEngine.XR.InputDevice>();
    4.     UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, rightHandDevices);
    5.     if (rightHandDevices.Count > 0)
    6.     {
    7.         var device = rightHandDevices[0];
    8.  
    9.         bool GripValue;
    10.         if (device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.gripButton, out GripValue) && GripValue)
    11.         {
    12.             Debug.Log("Right grip button is pressed");
    13.         }
    14.     }
    15. }
    Hope that helps!

    Arron
     
    Last edited: Sep 15, 2019
    ROBYER1 likes this.