Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// An extra script for this repository: https://github.com/paganini24/UnityAndroidExtraPlugins
- /// </summary>
- public class AskQuit : MonoBehaviour {
- public float timeTreshold = 2f;
- float timeCounter = 0f;
- int count = 0;
- void Start ()
- {
- UnityAndroidExtras.instance.Init();
- }
- void Update () {
- if(Input.GetKeyDown(KeyCode.Escape))
- {
- count++;
- if (count == 1)
- {
- UnityAndroidExtras.instance.makeToast("Please press back button again to exit", 1);
- }
- else if (count == 2 && timeCounter < timeTreshold)
- {
- Application.Quit();
- }
- }
- // count time if clicked first time
- if(count == 1)
- {
- timeCounter += Time.deltaTime;
- }
- if(timeCounter > timeTreshold)
- {
- timeCounter = 0f;
- count = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement