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

Using Androids Back Button

Discussion in 'Android' started by mark-pollard, Jul 15, 2015.

  1. mark-pollard

    mark-pollard

    Joined:
    Apr 2, 2013
    Posts:
    14
    Hi

    I have been using this code in my project hoping that the android back button will work.

    voidUpdate()
    {
    if (Input.GetKey (KeyCode.Escape))
    {
    ExitCam();
    Application.LoadLevel ("Escape");
    }
    }

    But it won't register the back button it at all.

    I have tried
    if (Input.GetKey (KeyCode.Escape))
    and
    if (Input.GetKeyDown (KeyCode.Escape))

    it still won't work :(

    I am using unity5 and a samsung tablet.

    Edit - Sorry i did try Escape as well
     
    Last edited: Jul 16, 2015
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    For the back button on mobile, you should check for KeyCode.Escape
     
  3. mark-pollard

    mark-pollard

    Joined:
    Apr 2, 2013
    Posts:
    14
    Yes i did try this and it still didn't work on my samsung mobile.
     
  4. Peecha

    Peecha

    Joined:
    Dec 2, 2013
    Posts:
    22
    Hello, are you using any plugins (ads, etc.)? I was using chartboost in my project and it was blocking the back button event.
     
  5. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,796
    Use Input.GetKeyUp instead of Input.GetKey

    GetKey in some instances may fire multiple times, you only want it to fire once.
     
  6. mark-pollard

    mark-pollard

    Joined:
    Apr 2, 2013
    Posts:
    14
    meltdown look i said this in the post

    I have tried
    if (Input.GetKey (KeyCode.Escape))
    and
    if (Input.GetKeyDown (KeyCode.Escape)

    Peecha: i am only using my plugin which i made in eclipse.
     
  7. screenname_taken

    screenname_taken

    Joined:
    Apr 8, 2013
    Posts:
    663
    I'm using
    if (Input.GetKeyUp("escape")){
    Application.Quit();
    }

    And it works. If it doesn't perhaps Sammy is doing something funky.