Skip to content

Instantly share code, notes, and snippets.

@natsupy
Last active August 27, 2017 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natsupy/e6a7f8a949c21aaf321d6960e4a48212 to your computer and use it in GitHub Desktop.
Save natsupy/e6a7f8a949c21aaf321d6960e4a48212 to your computer and use it in GitHub Desktop.
Quit App in key Esc(PC) a.k.a Back Button on Android
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
OnClickBackButtonQuit();
}
}
bool isFirstPress = false;
float timeFirstPress;
void OnClickBackButtonQuit()
{
if (!isFirstPress)
{
timeFirstPress = Time.realtimeSinceStartup;
//Do Something
//OnShowBadInternet("Press Back again to quit Application!", 3);
isFirstPress = true;
}
else
{
var timeDoublePress = Time.realtimeSinceStartup - timeFirstPress;
isFirstPress = false;
if (timeDoublePress < 3)
{
Application.Quit();
print("Quit");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment