Last active
August 27, 2017 21:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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