Hi,
How can I check to see if the device has a compass?
Thanks
Hi,
How can I check to see if the device has a compass?
Thanks
This seems to work: Try setting and reading Input.compass.enabled. If you enable it but it still read false, there’s no compass.
Thanks, will give this a go
Reading Input.compass.enabled is not working for me (at least not on my iPhone).
I’m not sure how accurate this is, but here’s what I did:
private IEnumerator IsCompassAvailable () {
bool compass = false;
for (int i = 0; i < 10; i++) {
if (Input.compass.trueHeading != 0) {
compass = true;
}
yield return new WaitForSeconds(0.05f);
}
yield return compass;
}
Basically I take 10 samples of the sensor across 500ms, if they are all equal to 0 I assume that there is no compass available (this probably works with magneticHeading too).
Obviously you need to enable the compass beforehand.
I hope this helps someone!