I'm trying to make an app that responds to the Cardboard.SDK.Tilted flag in some Update() method.
When running in Unity Player, by pressing the Esc button, Cardboard.SDK.Tilted is set to true, so here's all good. But when i Build the app for Android, Cardboard.SDK.Tilted stays false if I tilt the device. Other VR apps with tilt actions work fine on my phone. Is there any other option I have to enable before building for Android to make this work?
I'm using Unity v5.3.3f1 and a Cardboard SDK v0.6, the devices I've tried on are Xperia Z2, Samsung Galaxy S3 and iPhone 6.
EDIT: So, I've tried putting this code into both Update() and LateUpdate() methods:
if (Cardboard.SDK.Tilted) {
print("tilted, next scene");
NextScene ();
}
When the screen is tilted, new scene should be loaded. But as I've said, it works only in Unity Player by pressing the Esc button to trigger the tilt, on a real device nothing happens - the Cardboard.SDK.Tilted variable is never set to true.
I've seen on https://recordnotfound.com/cardboard-unity-googlesamples-6780/issues that there was a issue of discontinuation of Tilt in v0.6, is it possible that this is no longer supported? But it's strange that it works in Unity Player but not on a real device.
I can verify that the Cardboard.SDK.Tilted flag does not appear to working as in previous versions of the SDK. The escape button triggers it in the debugger, but the tilt action does not trigger it in builds.
However, you can implement an equivalent quite simply with Input.acceleration:
float angle = 80.0f / 360.0f * 2.0f * Mathf.PI;
bool isTilted = Mathf.Abs(Input.acceleration.normalized.x) > Mathf.Sin(angle);
if (Cardboard.SDK.Tilted || isTilted)
{
//Action here
}
If the device's acceleration is entirely due to gravity, the angle float is the angle of the device from horizontal. Attempting to normalize a Vector3 that is too small sets it to zero, so small vectors shouldn't trip the conditional. Pre-calculate your sine to save a cycle.