Advertisement
Guest User

AskQuit

a guest
Mar 10th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement