I am building a VR application with a menu scene and many other scenes.. I would like to get back into the menu scene from any other scene when the user hits the mobiles back button (android).. What is the script for that and where should i place the script??
In Unity, the Android back button is treated the same as the "Escape" KeyCode. So in order to do something when the user presses the back button on their Android device, you need to check for the Escape key being pressed down and also make sure the user is on the Android platform (if you're cross-platform).
Input. backButtonLeavesApp=true; Add this line to the update function of your code. It will terminate the application on an android phone when the user presses the back button.
You use the Escape
keycode to detect back button press on Android.
using UnityEngine.SceneManagement;
void Update()
{
if (Input.GetKey(KeyCode.Escape))
{
SceneManager.LoadScene("Main Menu");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With