Cardboard Back button?

I made a Cardboard project but it does not exit when you press the back button. How do I make it do so?

I found this http://iswwwup.com/t/c876c8a52695/google-cardboard-unity-sdk-detecting-back-button-press.html which says it’s an option, but nothing about how to turn this option on.

I could add my own response to KeyCode.Escape, but the Cardboard is also supposed to do it when you flick it down & to the right & I wouldn’t want to re-implement that if there’s an existing thing to do.

Okay, I went through the cardboard source & found the OnTilt action.

GetComponent<Cardboard>().OnTilt += () => { Application.Quit(); };

Though I confirmed by playing some other Cardboard games that most don’t actually use the OnTilt as a back button, so I did end up just using KeyCode.Escape instead.

In SDK v0.5.2 there is now a configurable back button that can be displayed (you turn it on on the CardboardMain, which (a long with the hardware back button, and tilt) will trigger an OnBackButton event:

GetComponent<Cardboard>().OnBackButton += ()=>{Application.Quit(); };

When the user clicked ✕ (close) or :arrow_backward: (back), the current Unity behavior is for your app to 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 the above is working as expected in Unity 5.6.2p3 using GVR SDK 1.70.0. Newer releases should work the same.

1 Like