Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Cardboard Back button?

Discussion in 'AR/VR (XR) Discussion' started by rrh, Aug 24, 2015.

  1. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
  2. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    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.
     
  3. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    Okay, I went through the cardboard source & found the OnTilt action.

    Code (csharp):
    1. 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.
     
  4. peterept2

    peterept2

    Joined:
    Aug 1, 2012
    Posts:
    41
    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:

    Code (CSharp):
    1. GetComponent<Cardboard>().OnBackButton += ()=>{Application.Quit(); };
     
  5. fredsa

    fredsa

    Joined:
    May 31, 2015
    Posts:
    19
    When the user clicked ✕ (close) or ◀ (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:

    Code (CSharp):
    1. void Update() {
    2.   if (Input.GetKeyDown(KeyCode.Escape)) {
    3.     // Android close icon or back button tapped.
    4.     Application.Quit();
    5.   }
    6. }

    In development and testing you can inject an artificial escape press using:

    Code (Bash):
    1. 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.
     
    Last edited: Aug 9, 2017
    DHein likes this.