Shegotwet/Assets/Scripts/UI/ToastUI.cs

31 lines
794 B
C#
Raw Normal View History

using TMPro;
using UnityEngine;
public class ToastUI : MonoBehaviour
{
2025-09-13 21:35:38 +00:00
public RectTransform rt_bg;
public TextMeshProUGUI t_mgs;
Vector2 basePos; // 기준 위치 저장용
private void Awake()
{
basePos = (transform as RectTransform).anchoredPosition;
}
public void Set(string text, float y = 0f)
{
gameObject.SetActive(true);
t_mgs.text = text;
2025-09-13 21:35:38 +00:00
rt_bg.sizeDelta = new Vector2(rt_bg.sizeDelta.x, t_mgs.preferredHeight + 50);
// 위치 조정 (y값 있으면 기준 위치에서 더함)
var rt = transform as RectTransform;
rt.anchoredPosition = basePos + new Vector2(0f, y);
if (IsInvoking()) CancelInvoke();
Invoke("Off", 3f);
}
void Off() { gameObject.SetActive(false); }
}