rabidus-test/Assets/Scripts/UIPanel.cs

57 lines
1.2 KiB
C#
Raw Permalink Normal View History

2023-08-15 17:38:54 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIPanel : MonoBehaviour
{
public bool HideOnStart = true;
public bool UseScale = true;
public float ScaleTime = 0.5f;
private CanvasGroup canvasGroup;
private void Awake()
{
canvasGroup = GetComponent<CanvasGroup>();
}
private void Start()
{
if (HideOnStart)
{
canvasGroup.alpha = 0;
canvasGroup.blocksRaycasts = false;
}
}
public void ShowPanel()
{
if (UseScale)
{
gameObject.transform.localScale = Vector3.zero;
gameObject.LeanScale(Vector3.one, 0.5f);
}
canvasGroup.alpha = 1;
canvasGroup.blocksRaycasts = true;
}
public void HidePanel()
{
if (UseScale)
{
gameObject.transform.localScale = Vector3.one;
gameObject.LeanScale(Vector3.zero, 0.5f).setOnComplete(() =>
{
canvasGroup.alpha = 0;
canvasGroup.blocksRaycasts = false;
});
}
else
{
canvasGroup.alpha = 0;
canvasGroup.blocksRaycasts = false;
}
}
}