// Made w/ love by Nuark Noir from Caffeine Agency // Keep this header if you like my work using System.Collections; using DG.Tweening; using UnityEngine; using UnityEngine.UI; public class OffCanvasMenu : MonoBehaviour { [SerializeField] private Image offMenuBody; [SerializeField] private KeyCode menuOpenButton = KeyCode.Escape; private int w = 200; private bool isOpen = false, opening = false; void Update() { if (Input.GetKeyDown(menuOpenButton) && !opening) { StartCoroutine(MenuOpenCoroutine()); } } IEnumerator MenuOpenCoroutine() { opening = true; var loc = offMenuBody.rectTransform.localPosition; if (isOpen) { _mouseHider.Hide(); offMenuBody.rectTransform.DOMoveX(0, 1f, true).SetUpdate(true); Time.timeScale = 1f; } else { Time.timeScale = 0f; offMenuBody.rectTransform.DOMoveX(w, 1f, true).SetUpdate(true); _mouseHider.Show(); } isOpen = !isOpen; opening = false; yield return null; } public void CloseGame() { Application.Quit(); } }