- Home /
back button in Android Activity
I'm trying to integrate Unity game project into a Android project in Eclipse following the User Manual. Now the game is successfully integrated into an new activity creating when user press a button in main activity. But when user pressed the android's own 'back' button, nothing happened.
How can I make it to work like: when user presses 'back' button, go back to main activity(like in a normal android apps)?
Please share how you made a Unity Game become an Activity in your Android project? What user User $$anonymous$$anual did you follow to accomplish this goal?
Answer by Paulius-Liekis · Jun 07, 2011 at 09:45 AM
Do this in one of your scripts (KeyCode.Escape is code for native "Back" button on Android):
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
or something like that :)
where do i add this script?' i mean shoud i creat a new java script and add on each level? or an objects?
Just create a new JavaScript or C# script and place these lines into Update call. Attach the script to any active GameObject (for example camera).
thanks cz i did it on my backgroud, i tought it was wrong....
You must create a new C# script and attach that script to any active GameObject (like Paulius-Liekis wrote). In the script you can use the Update method:
/** Update is called once per graphical frame */
void Update()
{
// Close app if back button is pressed
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
Application.Quit();
}
Your answer
Follow this Question
Related Questions
How can I use Unity Android in an Android Application view sub section? 2 Answers
Unity freeze on finished exporting eclipse project 1 Answer
Unity Android -> ADT (Eclipse) Assets are corrupted ? 2 Answers
Exporting Google Android project from Unity 4 to Android Studio issue 0 Answers
Android/Unity/Eclipse Help 0 Answers