-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\$
11
  • \$\begingroup\$ Is the script with this code attached to an object in the scene? Which object? \$\endgroup\$ Commented Nov 16, 2017 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\$ Commented Nov 16, 2017 at 19:22
  • \$\begingroup\$ Can you try attaching the script to your Main Camera - or something that takes input? \$\endgroup\$ Commented Nov 16, 2017 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
    Commented Nov 16, 2017 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\$ Commented Nov 16, 2017 at 20:29

1 Answer 1

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\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .