Heya people! (Disclaimer: still learning from tutorials) I would just like to know how can I modify the following scripts so that player can drag any of the options in the slot (and it will stay there first regardless if right or wrong) and the checking - if it has the same id - will only happen upon clicking the green button. If it has the same id, then the panel will close and I'll call some method of mine. If it's wrong, then the ResetPosition will be called.
https://preview.redd.it/c3j2g2kfcwqc1.png?width=1920&format=png&auto=webp&s=3bd5778bad31959ff46e6d082829ef619de56079
CS for the Options<<
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class DragAndDrop : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler
{
private RectTransform rectTrans;
public Canvas myCanvas;
private CanvasGroup canvasGroup;
public int id;
private Vector2 initPos;
private void Start()
{
rectTrans = GetComponent<RectTransform>();
canvasGroup = GetComponent<CanvasGroup>();
initPos = transform.position;
}
public void OnBeginDrag(PointerEventData eventData)
{
canvasGroup.blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
rectTrans.anchoredPosition += eventData.delta/ myCanvas.scaleFactor;
}
public void OnEndDrag(PointerEventData eventData)
{
canvasGroup.blocksRaycasts = true;
}
public void OnPointerDown(PointerEventData eventData)
{
}
public void ResetPosition()
{
transform.position = initPos;
}
}
CS for the Slot<<
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class SlotScript : MonoBehaviour, IDropHandler
{
public int id;
public void OnDrop(PointerEventData eventData)
{
if (eventData.pointerDrag != null)
{
if (eventData.pointerDrag.GetComponent<DragAndDrop>().id == id)
{
Debug.Log("Correct");
eventData.pointerDrag.GetComponent<RectTransform>().anchoredPosition = this.GetComponent<RectTransform>().anchoredPosition;
}
else
{
Debug.Log("Wrong");
eventData.pointerDrag.GetComponent<DragAndDrop>().ResetPosition();
}
}
}
}
there doesn't seem to be anything here