Files
2026-05-29 18:21:53 +03:00

58 lines
1.4 KiB
C#

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DropZone : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
{
public int slotIndex;
public DraggableCard currentCard;
private Image image;
void Awake()
{
image = GetComponent<Image>();
}
public void OnDrop(PointerEventData eventData)
{
DraggableCard card = eventData.pointerDrag?.GetComponent<DraggableCard>();
if (card == null) return;
if (currentCard != null && currentCard != card)
currentCard.ReturnToOriginal();
currentCard = card;
card.transform.SetParent(transform);
card.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
}
public void OnPointerEnter(PointerEventData eventData)
{
if (image != null)
image.color = new Color(1f, 1f, 1f, 0.5f);
}
public void OnPointerExit(PointerEventData eventData)
{
if (image != null)
image.color = new Color(1f, 1f, 1f, 0.2f);
}
public void SetCorrect()
{
if (image != null) image.color = new Color(0f, 1f, 0f, 0.5f);
}
public void SetWrong()
{
if (image != null) image.color = new Color(1f, 0f, 0f, 0.5f);
}
public void ResetColor()
{
if (image != null) image.color = new Color(1f, 1f, 1f, 0.2f);
currentCard = null;
}
}