using System; using DG.Tweening; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace View { public class UIVisibility : MonoBehaviour { [SerializeField] private CanvasGroup ui; [SerializeField] private float fadeDuration = .5f; private bool _wasVisible = true; private void Update() { bool isPointerOver = EventSystem.current.IsPointerOverGameObject(); if (_wasVisible && !isPointerOver) { ui.DOFade(0, fadeDuration).SetDelay(5f); _wasVisible = false; return; } if (!_wasVisible && isPointerOver) { ui.DOFade(1, fadeDuration); _wasVisible = true; return; } } } }