SHARE
TWEET

AskQuit

a guest Mar 10th, 2015 205 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// An extra script for this repository: https://github.com/paganini24/UnityAndroidExtraPlugins
  5. /// </summary>
  6. public class AskQuit : MonoBehaviour {
  7.         public float timeTreshold = 2f;
  8.         float timeCounter = 0f;
  9.         int count = 0;
  10.        
  11.         void Start ()
  12.         {
  13.                 UnityAndroidExtras.instance.Init();
  14.         }
  15.        
  16.        
  17.         void Update () {
  18.                 if(Input.GetKeyDown(KeyCode.Escape))
  19.                 {
  20.                         count++;
  21.                         if (count == 1)
  22.                         {
  23.                                 UnityAndroidExtras.instance.makeToast("Please press back button again to exit", 1);
  24.                         }
  25.                         else if (count == 2 && timeCounter < timeTreshold)
  26.                         {
  27.                                 Application.Quit();
  28.                         }
  29.                 }
  30.                 // count time if clicked first time
  31.                 if(count == 1)
  32.                 {
  33.                         timeCounter += Time.deltaTime;
  34.                 }
  35.                 if(timeCounter > timeTreshold)
  36.                 {
  37.                         timeCounter = 0f;
  38.                         count = 0;
  39.                 }
  40.         }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top