I’ve been trying to implement some basic code just to read button presses on my Oculus Rift controllers, using XR toolkit. Based on the Unity XR documentation, I implemented code that looks something like this
public class ReadInput : MonoBehaviour
{
//Assigned to the RightHand Controller
public XRController controller = null;
bool buttonValue;
void Start (){
}
void Update()
{
if(controller.inputDevice.TryGetFeatureValue(CommonUsages.primaryButton, out buttonValue) && buttonValue)
{
Debug.Log(" pressing a");
}
}
However, when testing this I don’t get anything popping up on my console regardless of what buttons I’m pressing. What am I missing from this code to get things to work properly?
I updated the code according to the website. Still I’m not getting any feedback in the debug log. Where am I going wrong?
public class ReadInput : MonoBehaviour
{
//Assigned to the RightHand Controller
public XRController controller = null;
InputDevice device;
void Start (){
device = Input.GetDeviceAtXRNode(controller.controllerNode);
}
void Update()
{
if(device.TryGetFeatureValue(CommonUsages.primaryButton, out bool buttonValue) && buttonValue)
{
Debug.Log(" pressing a");
}
}
Your code appears correct now, and should crash if something obvious goes wrong (e.g. if you disconnected the headset).
So there’s something with your project (or your hardware). You’ll need to debug your setup - I recommend you run the debugger, look at what the actual values are at that line of code when it runs, and post here when you’ve found something that’s wrong.