Reputation: 53
I was wondering if there was a way to check whether the sensor detects an object in the HMD. Specifically, this is in regards to the current latest version of Unity and the Oculus Rift CV1.
The reason why I wish to do this is for pausing my game, when the user is not wearing their HMD.
Upvotes: 0
Views: 2815
Reputation: 125455
This depends on the Unity version and has changed over time. It's usually the VRDevice.isPresent
property which has been renamed on some version. There is an issue with it in the Unity 5.2 and below so VRSettings.loadedDevice
should be used for 5.2 and below.
For Unity 5.2 and below, you need the UnityEngine.VR
namespace:
if (VRSettings.loadedDevice != VRDeviceType.None)
{
}
For Unity 5.3 and above, you need the UnityEngine.VR
namespace
if (VRDevice.isPresent)
{
}
For Unity 2017.2 and above, you need the UnityEngine.XR
namespace:
if (XRDevice.isPresent)
{
}
The examples above check if the device is present. To check if they are in use by the user:
if (XRDevice.userPresence == UserPresenceState.Present)
{
}
or
if (VRDevice.userPresence == UserPresenceState.Present)
{
}
Upvotes: 1