Jump to content

[Unity3D] Get Proximity Sensor Status


Fangh
 Share

Recommended Posts

  • 4 months later...
  • 2 years later...

Sample code:

        public static bool IsUserPresence()
        {
#if UNITY_ANDROID
            if (ProximitySensor.current != null)
            {
                if (!ProximitySensor.current.IsActuated())
                    InputSystem.EnableDevice(ProximitySensor.current);

                return ProximitySensor.current.distance.ReadValue() < 1; // near p-sensor < 1cm
            }
            else
            {
                return false;
            }
#else
            return true;
#endif
        }
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...