Hello,
I created a GUI that is a Unity PC Standalone .exe file. I would like to have a background timer that will close this .exe app, running after a set time on it’s own. Don’t want a manual solution just a Automated process within the GUI itself. I looked around and found Application.Quit(), don’t know if that should be used. I’m a designer not a C sharp pro. Can someone help me?
When the GUI is running in Windows for 2 minutes it closes on it’s own.
Could I use something like this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Threading;
public class CountDown : MonoBehaviour {
public int timeLeft = 60;
public Text countdown;
void Start () {
StartCoroutine(“LoseTime”);
Time.timeScale = 1;
}
void Update () {
countdown.text = (“” + timeLeft);
}
IEnumerator LoseTime()
{
while (true) {
yield return new WaitForSeconds (1);
timeLeft–;
}
}
public void QuitGame()
{
Application.Quit();
}
}
void Start()
{
//Quit in 10 seconds
StartCoroutine(SelfDestructSequence(seconds:10));
}
private IEnumerator SelfDestructSequence(int seconds)
{
while(seconds > 0)
{
Debug.Log($"Quitting in {seconds} seconds...");
yield return new WaitForSeconds(1);
seconds--;
}
//If in editor then quite playmode, else if running build then quit application
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}