Reputation: 53
I am trying to figure out how to use the oculus remote in Unity3D 5.3.4f. I've found some documentation about OVR mapping, but I can't seem to figure it out.
What I want to achieve is when the middle button(Button.One) is clicked.
What I now use is this line of code
if (OVRInput.GetUp(OVRInput.Button.One))
{
Debug.Log("remote click");
}
But when I run the application I get this error.
NullReferenceException: Object reference not set to an instance of an object OVRInput.GetUp (Button virtualMask, Controller controllerMask) (at Assets/OVR/Scripts/OVRInput.cs:600) menuButtonHandler.Update () (at Assets/menuButtonHandler.cs:136)
Which can be found in this script
/// <summary>
/// Gets the current up state of the given virtual button mask with the given controller mask.
/// Returns true if any masked button was released this frame on any masked controller and no other masked button is still down this frame.
/// </summary>
public static bool GetUp(Button virtualMask, Controller controllerMask = Controller.Active)
{
return OVRManager.input.GetResolvedButtonUp(virtualMask, RawButton.None, controllerMask);
}
Has anyone used to Oculus remote controller before in unity and can help me out?
Thank you,
Johan
Upvotes: 5
Views: 8839
Reputation: 7552
To work with the input in the Unity Version 2017.1.1 you have first to download the "Oculus Utilities for Unity"
Oculus Utilities asset package for Unity
Then you have to import the package in Unity,
Go to:
-- "Asset" --> "Import package" --> "Custom package"
Browse your "Oculus Utilities download"
Click on import
Call the function "OVRInput.update()" before calling the input checking functions.
void Update ()
{
OVRInput.Update(); // Call before checking the input
if (OVRInput.Get(OVRInput.Button.DpadLeft)) {
print("left button pressed");
}
if (OVRInput.Get(OVRInput.Button.DpadRight)) {
print("right button pressed");
}
if (OVRInput.Get(OVRInput.Button.One)) {
print("round button pressed");
}
}
For more information about the OVRInput check this link
Upvotes: 1
Reputation: 46
One of the objects in that method likely needs to be initialized before you make the GetUp() call.
Take a close look at your init code, and any samples you may have -- I bet you'll find something missing after not too much looking. I'm not familiar with the Unity APIs, but if they are anything like the PC or mobile C++ APIs, chances are you missed a step, or forgot to start up the VR service.
Upvotes: 1