using UnityEngine; using UnityEngine.EventSystems; using TMPro; public class KartuHuruf : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler { public char isiHuruf; public TextMeshProUGUI teksHuruf; private Transform parentAwal; private CanvasGroup canvasGroup; private Vector3 posisiAwal; void Start() { canvasGroup = GetComponent(); teksHuruf.text = isiHuruf.ToString(); posisiAwal = transform.localPosition; } public void OnBeginDrag(PointerEventData eventData) { parentAwal = transform.parent; // Pindah ke paling depan layar saat di-drag transform.SetParent(transform.root); canvasGroup.blocksRaycasts = false; // Biar tembus ke slot di bawahnya } public void OnDrag(PointerEventData eventData) { transform.position = Input.mousePosition; } public void OnEndDrag(PointerEventData eventData) { canvasGroup.blocksRaycasts = true; if (transform.parent == transform.root) { // Kalau dilepas bukan di slot yang benar, balik ke posisi awal transform.SetParent(parentAwal); transform.localPosition = posisiAwal; } } public void SetSelesai() { this.enabled = false; // Matikan fitur drag canvasGroup.blocksRaycasts = true; } }