You can now also use UnityEngine.XR
and XRDevice.userPresence
without the need for additional API's :
https://docs.unity3d.com/ScriptReference/XR.XRDevice-userPresence.html
For example :
if(trackingPresence == true)
{
if(XRDevice.userPresence == UserPresenceState.Present && playerPresent == false)
{
playerPresent = true;
Debug.Log("[PLAYER PRESENCE DETECTOR] player is now present");
}
if(XRDevice.userPresence == UserPresenceState.NotPresent && playerPresent == true)
{
playerPresent = false;
Debug.Log("[PLAYER PRESENCE DETECTOR] player is now absent");
}
}
Edit : for latest versions of Unity, you can use XRDisplaySubsystem.running
: https://docs.unity3d.com/2020.3/Documentation/ScriptReference/XR.XRDisplaySubsystem.html