saucebear Posted October 23, 2016 Share Posted October 23, 2016 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 More sharing options...
Rockjaw Posted October 25, 2016 Share Posted October 25, 2016 or might be able to help you with this one, . I'm afraid my knowledge of C stops at, er, the letter of the alphabet. :) Link to comment Share on other sites More sharing options...
Funkeeh Posted October 25, 2016 Share Posted October 25, 2016 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 More sharing options...
dario Posted October 25, 2016 Share Posted October 25, 2016 hi saucebear, If you install the Vive Input Utility Unity plugin from the asset store here: https://www.assetstore.unity3d.com/en/#!/content/64219 It'll be as simple as just doing this: if(ViveInput.GetPressDown(HandRole.LeftHand, ControllerButton.Trigger)) { } Link to comment Share on other sites More sharing options...
Rockjaw Posted October 26, 2016 Share Posted October 26, 2016 , if either or 's solutions worked for you, click 'Accept as Solution' to mark the topic solved. Thanks! :) Link to comment Share on other sites More sharing options...
EmptyPipe Posted October 26, 2016 Share Posted October 26, 2016 Unity is proving to be an impressive suite for VR game development. Have you seen the user-created Teleportation plugins specifically for the Vive? Link to comment Share on other sites More sharing options...
dario Posted December 8, 2016 Share Posted December 8, 2016 Let us know what you think of the teleportation support in the Vive Input Utility plugin Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.