0
\$\begingroup\$

I want to show toast message when the user presses the back button. I am handling button using this code, which is in my Update function:

if (Input.GetKeyUp(KeyCode.Escape)) {
  print ("UPUP");       
  ToastHelper.ShowToast ("Back", false);
  //Application.Quit();
} 

ToastHelper is plugin here.

The issue is that the toast message shows up twice, so it seems like the back key is acting like it was pressed twice. I only want it to execute once.

\$\endgroup\$
  • \$\begingroup\$ Are you sure you're not calling that toast it somewhere else? If you're on visual-studio, can you right-click the ShowToast method and search for uses, to confirm this? \$\endgroup\$ – XenoRo Dec 7 '17 at 16:45
  • \$\begingroup\$ Yes i am sure, I call it only from that place. print statement execute two times that means Back call two times \$\endgroup\$ – Rupal Patel Dec 7 '17 at 16:48
  • \$\begingroup\$ @RupalPatel the sparse codesample you post seems to be using key-polling. Are you sure that you don't just keep the back key pressed long enough for your key-handler to poll twice? \$\endgroup\$ – dot_Sp0T Dec 7 '17 at 16:51
  • \$\begingroup\$ Yes i am sure, i just press Escape key and release as normal not long in pc still it shows two times, And I tested in mobile device, i press single back but it executes two times. \$\endgroup\$ – Rupal Patel Dec 7 '17 at 16:54
  • 3
    \$\begingroup\$ Do you maybe have that script on two different game objects? \$\endgroup\$ – Philipp Dec 7 '17 at 17:19
-1
\$\begingroup\$

Problem gets solved. Its due to same script attached to two gameobject.

\$\endgroup\$
  • \$\begingroup\$ Minus for what? \$\endgroup\$ – Rupal Patel Dec 8 '17 at 12:13

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.