rabidus-test/Assets/UIFader.cs

48 lines
899 B
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIFader : MonoBehaviour
{
2023-10-04 12:49:59 +03:00
public float FadeTime;
private CanvasGroup canvasGroup;
private void Awake()
{
canvasGroup = GetComponent<CanvasGroup>();
}
private bool isShow = true;
public void ShowPanel()
{
LeanTween.value(0, 1, FadeTime).setOnUpdate((float x) =>
{
canvasGroup.alpha = x;
});
canvasGroup.blocksRaycasts = true;
isShow = true;
}
public void HidePanel()
{
LeanTween.value(1, 0, FadeTime).setOnUpdate((float x) =>
{
canvasGroup.alpha = x;
});
canvasGroup.blocksRaycasts = false;
isShow = false;
}
public void Toggle()
{
if (isShow)
HidePanel();
else
ShowPanel();
}
}