fgm24/Assets/Scripts/UI/QuitGame.cs

49 lines
982 B
C#
Raw Normal View History

2024-02-04 08:40:08 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-02-07 21:47:09 +01:00
using UnityEngine.UI;
2024-02-04 11:37:29 +01:00
using UnityEngine.InputSystem;
2024-02-04 08:40:08 +01:00
2024-02-07 21:47:09 +01:00
#if UNITY_EDITOR
using UnityEditor;
#endif
2024-02-04 08:40:08 +01:00
public class QuitGame : MonoBehaviour
{
2024-02-07 21:47:09 +01:00
public Image QuitGraphic;
private float HoldTime = 0.0f;
2024-02-04 08:40:08 +01:00
public void Quit()
{
2024-02-07 21:47:09 +01:00
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
2024-02-04 08:40:08 +01:00
}
2024-02-04 11:37:29 +01:00
private void Update()
{
foreach (var controller in Gamepad.all)
{
if (controller.squareButton.IsPressed())
{
2024-02-07 21:47:09 +01:00
HoldTime += Time.deltaTime;
QuitGraphic.fillAmount = HoldTime/2f;
if (HoldTime > 2f)
Quit();
return;
2024-02-04 11:37:29 +01:00
}
}
2024-02-07 21:47:09 +01:00
// Debug.Log("C# even managed to fuck up return statements");
QuitGraphic.fillAmount = 1f;
HoldTime = 0.0f;
2024-02-04 11:37:29 +01:00
}
2024-02-04 08:40:08 +01:00
}