31 lines
No EOL
749 B
C#
31 lines
No EOL
749 B
C#
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 Tween _fadeTween;
|
|
|
|
private void Update() {
|
|
bool isPointerOver = EventSystem.current.IsPointerOverGameObject();
|
|
if (_wasVisible && !isPointerOver) {
|
|
_fadeTween?.Kill();
|
|
_fadeTween = ui.DOFade(0, fadeDuration).SetDelay(5f);
|
|
_wasVisible = false;
|
|
return;
|
|
}
|
|
if (!_wasVisible && isPointerOver) {
|
|
_fadeTween?.Kill();
|
|
_fadeTween = ui.DOFade(1, fadeDuration);
|
|
_wasVisible = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |