W_WuHuVR/Medicine/Assets/Scr/EndScr/GameQuit.cs

56 lines
1.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using System.Collections;
public class GameQuit : MonoBehaviour
{
private int mPressTimes = 0;
// Use this for initialization
void Start()
{
//Ensure that there is only one gameQuit in the Scene即使加载了下个场景Scene
//GameObject[] gameQuits = GameObject.FindGameObjectsWithTag("GameQuit");
//if (gameQuits.Length == 2)
//{
// Destroy(this.gameObject);
//}
DontDestroyOnLoad(this.gameObject);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{//KeyCode.Escape表示键盘ESC,手机的返回键
mPressTimes++;
StartCoroutine("ResetMPressTimes", 1.0f);//若过了1秒都没有按第2次则重置mPressTimes
if (mPressTimes == 2)
{
Application.Quit();
}
}
}
IEnumerator ResetMPressTimes(float sec)
{
yield return new WaitForSeconds(sec);
mPressTimes = 0;
}
}