-2
\$\begingroup\$

I take an empty gameobject and a script in which I just write below code to handle back button in android phone, but it's not working.

if (Input.GetKeyDown (KeyCode.Escape)){
            // Escape button pressed
            print("Escape");
}
\$\endgroup\$
  • \$\begingroup\$ Is the script with this code attached to an object in the scene? Which object? \$\endgroup\$ – Jesse Dorsey Nov 16 '17 at 19:20
  • \$\begingroup\$ Yes i take empty gameobject , and attached script with this gameobject. Update is executing but its not going to if stament. i am running game using unityRemote applciation in my phone \$\endgroup\$ – Rupal Patel Nov 16 '17 at 19:22
  • \$\begingroup\$ Can you try attaching the script to your Main Camera - or something that takes input? \$\endgroup\$ – Jesse Dorsey Nov 16 '17 at 19:25
  • \$\begingroup\$ Examples I've found seem to use the GetKeyUp method rather than the GetKeyDown method. Try making the change and see if it works. Android may not send the keydown event. \$\endgroup\$ – Stephan Nov 16 '17 at 19:37
  • 1
    \$\begingroup\$ Try this instead (outside the update method): OnApplicationPause(){print("Escape");} and let me know how it goes. Also, @Stephan InputManager doesn't have the Escape as a key, it's a built-in keycode (at least it is so in the latest version). \$\endgroup\$ – John Hamilton Nov 16 '17 at 20:29
1
\$\begingroup\$
if (Input.GetKeyDown (KeyCode.Escape)){ 
  // Escape button pressed print("Escape"); 
} 

This code is working. Problem was i was testing it through unity remote 5. that's why it was taking input from keyboard not from mobile, When i tested it by making apk its working.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.