feat: ui transparency when not hovered
This commit is contained in:
parent
88a97164ea
commit
12304c6bb4
366 changed files with 27618 additions and 28 deletions
28
Assets/Scripts/View/UIVisibility.cs
Normal file
28
Assets/Scripts/View/UIVisibility.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue