Reputation: 3
I'm wanting to use the back button to load a level in unity and I'm having trouble using BackButtonPressed to achieve this.
Disabling the Back button (Appearing on my phone as the close button though from what I've read on Cardboard this should run the BackButton Command) would also be alternative I can use. I'm using Google VR SDK 1.1 so the menu options for the interface are no longer there.
Any help would be appreciated, Thanks.
Upvotes: 0
Views: 1405
Reputation: 1022
When clicking ✕ (close) or ◀ (back), your Unity app will see an escape key press, which you can handle in your code by looking for the key down event:
void Update() {
if (Input.GetKeyDown(KeyCode.Escape)) {
// Android close icon or back button tapped.
Application.Quit();
}
}
In development and testing you can inject an artificial escape press using
$ adb shell input keyevent KEYCODE_ESCAPE
Note, the close button was briefly broken (mentioned here) due to a Unity bug (case 893219), but is now fixed (release notes).
Verified that this is working as expected in Unity 5.6.2p3 (recent QA patch release) using GVR SDK 1.70.0. Newer releases can be expected to work as well of course.
Upvotes: 1