Health/Assets/Scripts/UI/NotificationPopupUI.cs

35 lines
1022 B
C#
Raw Normal View History

2023-11-14 17:01:48 +00:00
using System;
2023-11-14 10:52:43 +00:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
2023-11-14 17:01:48 +00:00
public class NotificationPopupUI : MonoBehaviour
2023-11-14 10:52:43 +00:00
{
2023-11-14 17:01:48 +00:00
private TextMeshProUGUI _title;
private TextMeshProUGUI _description;
private Animator _animator;
2023-11-14 10:52:43 +00:00
private void Awake()
{
2023-11-14 17:01:48 +00:00
_title = transform.Find("Title").GetComponent<TextMeshProUGUI>();
_description = transform.Find("Description").GetComponent<TextMeshProUGUI>();
_animator = GetComponent<Animator>();
transform.gameObject.SetActive(true);
transform.GetComponent<CanvasGroup>().alpha = 0;
2023-11-14 10:52:43 +00:00
}
2023-11-14 17:01:48 +00:00
public IEnumerator Show(string title, string content)
2023-11-14 10:52:43 +00:00
{
2023-11-14 17:01:48 +00:00
if (!transform.gameObject.activeSelf)
transform.gameObject.SetActive(true);
transform.GetComponent<CanvasGroup>().alpha = 0;
2023-11-14 10:52:43 +00:00
2023-11-14 17:01:48 +00:00
_title.text = title;
_description.text = content;
_animator.Play("In");
yield return new WaitForSeconds(3f);
_animator.Play("Out");
2023-11-14 10:52:43 +00:00
}
}