- Home /
Using Android Back button to navigate backwards through a menu
Hi,
I'm trying to use the Back button on an Android device to go back to the previous screen in a menu, rather than using a 'Back' button on every screen. I've successfully turned Immersive mode off after the splash screen (to display the Back, Home, and Minimise buttons).
However, when the Back button is pressed it minimises the app.
I'm using Unity 5.6.3f1 and a Sony Xperia Z5 phone.
I'm currently using the following code in the Update of a script which is on an object in the scene when the app starts:
if (Input.GetKeyDown(KeyCode.Escape))
{
if (Application.platform == RuntimePlatform.Android)
{
BackButtonPressed();
}
}
The BackButtonPressed() function works fine if used with a UI button on every screen but not when using the phone's button.
Any help with this would be great. Thanks in advance.
Answer by knorke · Oct 04, 2017 at 01:05 PM
Hard to tell what is causing this.
You might wanna try a different phone or emulator like nox/bluestacks, to get sure it is not your phone acting differently in this scenario.
Also could you explain why you use the if statement checking if the platform is android?