using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIDisplayMessage : MonoBehaviour { [SerializeField] private TMPro.TextMeshProUGUI _textField; [SerializeField] private UIProgressBar _progressBar; private float _time; public void Init(DisplayMessage info) { _textField.SetText(info.Message); _time = info.Time; Hide(); } public bool IsShow = false; private LTDescr LTDescr; public void Show() { if (IsShow) { LeanTween.cancel(LTDescr.id); LTDescr = LeanTween.value(1, 0, _time).setOnUpdate((float x) => { _progressBar.ChangeValue(x); }).setOnComplete(Hide); } else { IsShow = true; gameObject.SetActive(true); LTDescr = LeanTween.value(1, 0, _time).setOnUpdate((float x) => { _progressBar.ChangeValue(x); }).setOnComplete(Hide); } } public void Hide() { IsShow = false; gameObject.SetActive(false); } public void StopMessage() { Hide(); } }