- Home /
Unity iPhone - Do we get access to the iPhone's light sensor?
Do we get access to the light sensor information? I would like to know when a user has the phone pressed flat against his/her face or another surface.
Thanks
Mat
Answer by qJake · Sep 09, 2010 at 07:56 PM
I'm no Apple developer, so this is my guess, but from what I've read, it's not even accessible from Xcode, so my guess would be no. Even if it were available natively, you would still need to write an Xcode plugin for Unity to be able to handle that event (which requires Unity Pro).
And by the way, there are actually two sensors on the top of the iPhone - one is a photosensor that detects brightness conditions for auto-screen dim$$anonymous$$g, and the other is a simple proximity sensor that detects if an object is held close to the top of the phone (like your ear when you're in a call).
Does anyone know if it is still not accessible in Unity 2019 ? I wierdly can't find much info about that subject.
Answer by u3dxt · Jan 03, 2014 at 10:47 PM
Yes, it is one of the features of our iOS Unity plugin. We expose this functionality via the UIDevice class.
UIDevice device = UIDevice.CurrentDevice();
device.proximityMonitoringEnabled = true; // need to enable this first
then you can just read device.proximityState to check if the user is close to the sensor. Or you can also monitor the UIDevice.UIDeviceProximityStateDidChangeNotification event to get a notified when the sensor state changes.
@ina, yeah. you know how when you answer a phone call the phone screen dims as you bring it closer to your face? it senses that using the proximity sensor. now you can use it for your unity games. heh.
Could you please help me, I already downloaded iOS Unity plugin, and still can't use UIDevice device = UIDevice.CurrentDevice(); device.proximity$$anonymous$$onitoringEnabled = true; Thank you in advance.