rabidus-test/Assets/Scripts/UIDisplayMessage.cs

56 lines
1.0 KiB
C#
Raw Normal View History

2023-09-04 12:48:24 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIDisplayMessage : MonoBehaviour
{
[SerializeField]
private TMPro.TextMeshProUGUI _textField;
2023-09-11 15:44:17 +03:00
private LeanTimer _leanTimer;
private void Awake()
{
_leanTimer = GetComponent<LeanTimer>();
}
2023-09-04 12:48:24 +03:00
2023-09-05 17:38:11 +03:00
private float _time;
2023-09-04 12:48:24 +03:00
public void Init(DisplayMessage info)
{
_textField.SetText(info.Message);
2023-09-05 17:38:11 +03:00
_time = info.Time;
Hide();
}
public bool IsShow = false;
public void Show()
{
if (IsShow)
{
2023-09-11 15:44:17 +03:00
_leanTimer.StopTimer();
_leanTimer.StartTimer(1, 0, _time, Hide);
2023-09-05 17:38:11 +03:00
}
else
{
IsShow = true;
gameObject.SetActive(true);
2023-09-11 15:44:17 +03:00
_leanTimer.StartTimer(1, 0, _time, Hide);
2023-09-05 17:38:11 +03:00
}
}
public void Hide()
{
IsShow = false;
2023-10-11 17:33:14 +03:00
if (gameObject != null)
gameObject.SetActive(false);
2023-09-05 17:38:11 +03:00
}
public void StopMessage()
{
Hide();
2023-09-04 12:48:24 +03:00
}
}