initial commit
This commit is contained in:
57
Assets/Scripts/DropZone.cs
Normal file
57
Assets/Scripts/DropZone.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user