Hello, I've read many topics about Back button on Android, but none of there mentioned solutions worked for me. Android 4.4.2 Can anyone please share with a working solution, that captures some value (1 or true), when Back button is being pressed and not a frame longer? What I've tried: Code (CSharp): if(Input.GetKeyDown(KeyCode.Escape)) and Code (CSharp): if(Input.GetKey(KeyCode.Escape)) Works great in Unity Editor, doesn't work on phone (no reaction) Then in InputManager's Axes I created a custom axes called Escape with Positive Button = escape Afterwards I've tried: Code (CSharp): if(Input.GetButton("Escape")) Works great in Unity Editor, but on phone captures a lot more than a single click - because of --- Code (CSharp): if(Input.GetButtonDown ("Escape")) Works great in Unity Editor, but doesn't work on phone (no reaction) Last one - created a variable PrevAxis, which stores GetAxis("Escape") value from previous frame: Code (CSharp): private float PrevAxis=0; then in Update() added lines, that check, if Escape is pressed and was it pressed in a previous frame: Code (CSharp): if((Input.GetAxis ("Escape")==1)&&(PrevAxis==0)) { } PrevAxis = Input.GetAxis ("Escape"); And again : works great in Unity Editor, but on phone doesn't work at all (no reaction) P.S. With "no reaction" I mean - no reaction in my game, because when I press Back button, my phone vibrates as it should.
Hmmm, not sure I have an answer for you, but I can confirm that we use "Input.GetKeyDown(KeyCode.Escape)" in all our games and it works fine. Just tested on our device running 4.4.4 and it works. Our code is pretty simple: in Update(), we just check Input.GetKeyDown(KeyCode.Escape) and then do any processing as a result.
Interesting, I'm doing exactly the same, but once again : in Unity Editor everything works fine (on keyboard's Esc), but on phone - just vibrates and does nothing. Tried on two different phones (4.2 and 4.4). Both phones have sensor buttons below screen. Code (CSharp): void Update () { if(Input.GetKeyDown(KeyCode.Escape)) { //Do something! } } Any ideas?
What are you trying to do when the back button is pressed? Are you using Debug.Log to log its actually being pressed and looking at the logs as its happening?
No good ideas here unfortunately, but I can confirm that it works fine for me as well... Android 4.4.4 Perhaps try a blank project with a simple action to see if it works in that case?
if (Application.platform == RuntimePlatform.Android) { if (Input.GetKey(KeyCode.Escape)) { // Insert Code Here (I.E. Load Scene, Etc) // OR Application.Quit(); return; }