using TMPro; using UnityEngine; public class ToastUI : MonoBehaviour { 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; 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); } }