feat: ui transparency when not hovered

This commit is contained in:
Gerard Gascón 2024-04-12 20:18:06 +02:00
parent 88a97164ea
commit 12304c6bb4
366 changed files with 27618 additions and 28 deletions

View file

@ -0,0 +1,28 @@
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);
_wasVisible = false;
return;
}
if (!_wasVisible && isPointerOver) {
ui.DOFade(1, fadeDuration);
_wasVisible = true;
return;
}
}
}
}