Jump to content

Unity developement question


saucebear

Recommended Posts

I'm creating my first VR program for Unity 3D. What I'm trying to do is make it so every button on the controller triggers a different action. I know C Sharp well enough to do this, but the problem is, I can't figure out how to detect controller button presses in C Sharp.

 

Any suggestions or ideas are appreciated,

Thanks

Link to comment
Share on other sites

You can access all the buttons and triggers via the SteamVR_Controller script you just need to assign a device to it. If you open the script, the "ButtonMask" class shows you which you can access. 

 

As an example, I use the "trigger" button in my script here:

public SteamVR_TrackedObject   trackedObj; //tracked object, the connected controller
public SteamVR_Controller.Device   device; //device object

public bool pressingTrigger;

 

void Awake ()
{
     trackedObj = GetComponent<SteamVR_TrackedObject>();
}

 

void FixedUpdate ()
{
     //Get input from the tracked object (which this script is attached to)
     device = SteamVR_Controller.Input( (int)trackedObj.index );

 

     //Get pressed value from "Trigger" button (between 0 and 1)
     Vector2 value = device.GetAxis ( Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger );
     float trigger = value.x;

     if (device.GetTouch (SteamVR_Controller.ButtonMask.Trigger))
    {
             pressingTrigger = true;
     }
     else
     {
            pressingTrigger = false;
     }
}

 

Link to comment
Share on other sites

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...